Reputation: 11
I have problem with seo friendly url. I've try to change my url with .htaccess and off course I have problem.
My link in header for my contact page is like this:
index.php?=contact
So I wrote rules in .htaccess like this:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^contact index.php?=contact
And off course changed my link in header to be like this:
contact
And now when I click on contact on header I get nice url like this:
www.mywebsite.com/contact
But website lead me always to home page (index.php).
What I did wrong?
Upvotes: 0
Views: 378
Reputation: 11
I made this clear, and now working. I just changed link, and put page
. Static link working now for me, but how to write to dinamic link. For instance, my link is like this:
<a href=index.php?page=kategorije/$row[id_cat]/$newname>{$row['name']}</a>
$newname give "-" instead empty space between words.
And this kind of link give me this url:
www.mywebsite.com/index.php?page=category/3/The-Name-Of-Shop
How to write .htaccess to get:
www.mywebsite.com/The-Name-Of-Shop
Upvotes: 0
Reputation: 24448
Here give this a try and see how it works.
You have an =
between index.php?contact
Try removing that.
If you want to make all your links URL friendly and not just contact
you can do this.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) index.php?$1&%{QUERY_STRING} [L]
EDIT:
Your array is blank because you're not passing anything to it. I can't see how you check in your index.php
file but you typically pass parameters as item=value
like index.php?page=contact
. You're not giving it an item
using index.php=contact
so your array is blank with the mod_rewrite.
Based on the info I have, if you used the variable as the item
and value
like below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?$1=$1&%{QUERY_STRING} [L]
Go to http://www.yoursite.com/contact
You'll get this from PHP $_GET
Array ( [contact] => contact )
But if you do this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?page=$1&%{QUERY_STRING} [L]
Then go to http://www.yoursite.com/contact
Then you'll get this from PHP $_GET
Array ( [page] => contact )
Then you check it like
if($_GET["page"] == "contact"){
//do whatever
}else{
//show homepage
}
There is nothing wrong with the .htaccess rules I can see. It's your PHP setup.
Upvotes: 0