Forum Moderators: phranque
from:
www.example.com/page.htm
to:
www.example.com/page.htm?Itemid=0
Unluckily Google has indexed those pages and now we are trying to redirect the extensions from .htm?Itemid=0 to .htm
This is what we're trying:
RewriteRule (.*).htm?Itemid=0$ /$1.htm [R=301,L]
but nothing happnes, redirect not happening.
We've tried several other attempts without success.
Any idea?
%{QUERY_STRING} part with a separate RewriteCond as the RewriteRule cannot see the query string. This stuff comes up almost every day. There are several open threads in the last few days with the code you need, as well as examples linked to from the sticky thread at the top of the page. This redirect is only one of several that may be needed to fix all the canonical issues you may encounter.
.
You need to be very clear which server paths are valid, and which external URLs you want your users to be able your content through. You'll use rewrites to connect URLs to server paths, and redirects from non-canonical URLs to the canonical formats to ensure that Google only "sees" one URL for each "page" of content, and that all other alternative URLs issue a redirect.
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /page\.htm\?Itemid=[^&\ ]*\ HTTP/
As I said in my previous post, the redirects seem to work just fine.
However, google webmaster tools is listing the pages with redirects in the "not followed" list, and the error is "empty redirect".
So somehow, while the redirect works via browsers, google can't follow the redirects correctly, and I think it will not drop those pages from the index.
Any idea on why this is happening?
# Strip Itemid query strings from all client-requested URL-paths
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?]*\?Itemid=[^&\ ]*\ HTTP/
RewriteRule (.*) http://www.example.com/$1? [R=301,L]
URLs which match the query string description after being internally rewritten by other code will not be redirected, because those other internal rewrites cannot change the value of "THE_REQUEST" as received from the HTTP client. This prevents an 'infinite' rewrite-redirect loop.
Jim
Jim
Testing using HTTP headers, after the GET for:
www.example.com/page?Itemid=0
I see an HTTP/1.x 301 Moved Permanently and the location is right, so everything seems to be working.
Thanks again, the things I've learned are precious for me.