Mobile app version of vmapp.org
Login or Join
Pope3001725

: How to 301 redirect from old query string URLs to CakePHP Canonical URLs? I currently have a .htaccess file that looks like this: RewriteCond %{QUERY_STRING} ^action=view&item=([0-9]+)$ RewriteRule

@Pope3001725

Posted in: #301Redirect #Htaccess #ModRewrite

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= [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= [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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Pope3001725

2 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

Quoting from the mod_rewrite documentation:


"You will almost always want to use [R] in conjunction with [L] (that is, use [R,L]) because on its own, the [R] flag prepends thishost[:thisport] to the URI, but then passes this on to the next rule in the ruleset, which can often result in 'Invalid URI in request' warnings."


In fact, I'd recommend using [NS,L,R=code] for external redirects, unless you have a particular reason to rewrite subrequests too.

Ps. This is what Google has to say about "Not Followed" errors. It looks like a malformed redirect is indeed a likely cause of them. Besides adding the missing [L] flag, I'd suggest using something like Firebug's Net panel to see exactly what your server is sending back in the Location header.

10% popularity Vote Up Vote Down


 

@Jessie594

What can I do to send both Google and users to the proper page and
save my PageRank?


Just to be certain: you're not redirecting Google and users differently, are you?

Sorry if I'm mistaken about this, as I don't know regex but it looks like you're rewriting the URL twice? Is that correct?

RewriteRule ^index.php$ /item/%1 [R=301]
RewriteRule ^(.*)$ index.php?url= [QSA,L]


Wouldn't that be considered a redirect loop?

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme