How to 301 redirect from old query string urls to CakePHP Canonical urls?
- by Daniel Bingham
I currently have a .htaccess file that looks like this:
RewriteCond %{QUERY_STRING} ^action=view&item=([0-9]+)$
RewriteRule ^index\.php$ /index.php?url=item/%1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
It is meant to 301 redirect my old query string based URLs to new CakePHP urls. This will successfully send users to the correct page. However, Google doesn't seem to like it (see below). I previously tried doing this:
RewriteCond %{QUERY_STRING} ^action=view&item=([0-9]+)$
RewriteRule ^index\.php$ /item/%1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
But that fails. The second rewrite rule doesn't seem to catch the rewritten URL. It goes straight through.
Using the first version wouldn't be a problem, except that I suspect that is what is choking up Google. It hasn't indexed my sitemap full of the new URLs. My old sitemap had been fully indexed and all the URLs are in Google's index. But it isn't following the redirects from the old URLs to the new. I have a 'not followed' error for every one of the query urls that was in my old sitemap.
Am I properly using a 301 redirect here? Is it the weird rewrite rule? What can I do to send both Google and users to the proper page and save my page rank?