Reputation: 131
I am trying to create seo-friendly URLs from my dynamic ones with a .htaccess rewrite. I've tried a ton of different rewrites and none of them are updating the URL. My other URL rewrite condition works fine...removing ".php" from the end of the URL.
Example:
Trying to change this:
food-truck.php?city=miami-fl&name=john doe
To this:
food-truck/city/miami-fl/name/john%20doe
Here is one of the rewrites I have tried with no success:
Options +FollowSymLinks
RewriteEngine on
RewriteRule food-truck/city/(.*)/name/(.*)/ food-truck.php?city=$1&name=$2
Any suggestions appreciated. Haven't been able to figure out a solution from similar questions in Stack Overflow posts or forums.
Thank you.
EDIT: Here is what did the trick...
RewriteCond %{QUERY_STRING} ^city=([^&\s]+)&name=([^&\s]+)$
RewriteRule ^(?:food\.php|)$ /%1?/%2? [R=301,L]
RewriteCond %{QUERY_STRING} ^city=([^&\s]+)&name=([^&\s]+)$
RewriteRule ^(?:food\.php|)$ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\s\/]+)/?$ food.php?city=$1&rname=$2&r [L,QSA]
Upvotes: 0
Views: 414
Reputation: 124
There is an extra slash in the end of your rule. Try to remove it:
RewriteRule food-truck/city/(.*)/name/(.*) food-truck.php?city=$1&name=$2
Also maybe you need to add the beginning and end:
RewriteRule ^food-truck/city/(.*)/name/(.*)$ food-truck.php?city=$1&name=$2
Upvotes: 1