I have created a simple dynamic website with php and I am having trouble making my URL structure search engine friendly. What I am trying to do is redirect links like this www.example.com/index.php?page=animals Code (markup): to this (including a trailing backslash) www.example.com/animals/ Code (markup): I have spent ages searching for a solution and found the below is the only one that actually lets the new URL work but I can't redirect it. It seems to be backwards to every other solution I have seen, when I add R=301 into the rule it redirects the nice url to the long version. RewriteEngine On RewriteRule ^([^/\.]+)/$ /index.php?page=$1 [L] Code (markup): So in short the two problems I have with this are: 1. It doesn't actually redirect the URL, it just allows both version to work. 2. If I tried to use the new url without the trailing backslash www.example.com/animals Code (markup): it will just bring up the 404 page. It should redirect to the page with a trailing slash. Any help will be much appreciated Many thanks
There are many online mod_rewrite rules generators (just Google it) - here's one: http://www.webmaster-toolkit.com/mod_rewrite-rewriterule-generator.shtml You can also test your rules with something like http://martinmelin.se/rewrite-rule-tester/
Try maybe something like this: RewriteEngine On RewriteBase / RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L] Code (markup): The question mark between /?$ will fix the trailing trash problem. Both url's will work, yes.