I'm currently rewriting my website to get some SEO URLs. It was working pretty good, but now I'm stuck at my final 301 redirects. I'd like to redirect the old dynamic URLs to the new static URLs (to prevent duplicate content). Examples: forum/viewforum.php?forum_id=123 ==> redirect to forum/forum-123/ forum/forum-123 ==> redirect to forum/forum-123/ (must have trailing slash) forum/forum-123/ ==> stays like this, but apache handles this as forum/viewforum.php?forum_id=123 This all works, but the pages don't get displayed. I always get: These are my rewriting rules: # Force trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://www.mysite.com/$1/ [L,R=301] # Forum SEO URL RewriteRule ^forum/forum-([0-9]+)/$ forum/viewforum.php?forum_id=$1 [L] # Redirect old dynamic URL RewriteCond %{QUERY_STRING} forum_id=([0-9]+) RewriteRule ^forum/viewforum.php$ http://www.mysite.com/forum/forum-%1/? [R=301,L] Code (markup): If anyone could point me into the right direction Thanks!
Try taking out the domain: # Redirect old dynamic URL RewriteCond %{QUERY_STRING} forum_id=([0-9]+) RewriteRule ^forum/viewforum.php$ forum/forum-%1/? [R=301,L] Code (markup):
Then I get my local path in the addressbar: http://localhost/C:/xampp/xampplite/htdocs/testing/forum/forum-111/
Where exactly are you working and what is your set up? The htaccess file you originally posted contains domains so that would indicate that your working on a remote server, but the error you just posted indicates your working locally in a xampp set up.
Well actually it's like this (testing locally): # Force trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://localhost/testing/$1/ [L,R=301] # Forum SEO URL RewriteRule ^forum/forum-([0-9]+)/$ forum/viewforum.php?forum_id=$1 [L] # Redirect old dynamic URL RewriteCond %{QUERY_STRING} forum_id=([0-9]+) RewriteRule ^forum/viewforum.php$ http://localhost/testing/forum/forum-%1/? [R=301,L] Code (markup):
Ok, so lets just work with the local and then once you have it working you can add in the domains later. One thing that is confusing me is the "testing" directory, you have it in the first rule, not at all in the second rule and then half in the third rule. Give this version a try and see where it gets you: # Force trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://localhost/testing/$1/ [L,R=301] # Forum SEO URL RewriteRule ^testing/forum/forum-([0-9]+)/$ /testing/forum/viewforum.php?forum_id=$1 [L] # Redirect old dynamic URL RewriteCond %{QUERY_STRING} forum_id=([0-9]+) RewriteRule ^testing/forum/viewforum.php$ /testing/forum/forum-%1/? [R=301,L] Code (markup):
What do the error log files tell you? They can be a great help in determining whats wrong with the htaccess.
That tells us that it isn't running the second rule. Try changing [R=301,L] to [R=301] on the third rule and see if that gives the same errors.