Forum Moderators: phranque
Problem is that the old site has {QUERY_STRING} parameters attached to the end of the main url which is severely interfering with se results.
So the domain [mydomain.com.au...] in google appears as [mydomain.com.au?page_id=13537....]
<snip>
I have gotten rid of all the other query string pages and this is the only one left but obviously the main one.
I am confused how to add the query string in the redirect code into .htaccess. When I try through Cpanel it doesnt work - it actually looks like it sends it into a loop.
Through Cpanel control panel via my host I used:
redirect 301 /?page_id=13537 http://www.example.com.au/
and .htaccess direct
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.example\.com\.au?page_id=13537
RewriteRule (.*) http://www.example.com.au/$1 [R=301,L]
Various other options too, but nothing has worked so far.
I still will have some pages that utilise query strings so dont want to change anything that will effect that just want to redirect this one querystring.
Just wondered what the actual code would be.
[edited by: jdMorgan at 1:55 am (utc) on Aug. 2, 2005]
[edit reason] Removed specifics per TOS. [/edit]
You just need to examine the query string using RewriteCond:
RewriteEngine on
#
# Skip next two rules if www domain request or if HTTP_HOST header in request is blank
RewriteCond %{HTTP_HOST} ^$¦^www\.example\.com\.au
RewriteRule .* - [S=2]
#
# Redirect request for "/" with specific query string in non-www
# domain to "/" in www domain, removing query string
RewriteCond %{QUERY_STRING} ^page_id=13537$
RewriteRule ^$ http://www.example.com.au/? [R=301,L]
#
# Redirect all other non-www pages to www domain pages, leaving queries intact
RewriteRule (.*) http://www.example.com.au/$1 [R=301,L]
#
# Skip=2 rule above skips to the first rule below this line.
#
Jim
I just got a little confused here. Not sure what you mean by "www domain request or if HTTP_HOST header in request is blank ". How would I check this for my problem... (excuse my ignorance on this subject)
The only problem I have is that of Google indexing - they have www.sitename.com.au/?blah=blah instead of www.sitename.com.au
Only the www no probems with non-www index as far as I can see. I am thinking of redirecting sitename.com.au to www.sitename.com.au but I just want to check into this a bit more for the benefits vs risks.
So to me the code here:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page_id=13537$
RewriteRule ^$ http://www.example.com.au/? [R=301,L]
does look more like what I am needing and actually just checked works visually anyway.
The problem with using a negative match pattern like !^www\.example\.co\.au is that a blank host header will match it, too. And a blank host header implies an HTTP/1.0 user-agent, or a broken user-agent. Either way, it will likely come back after a redirect, again with a blank user agent, and be redirected ad infinitum (well until the client or server times out, actually). So, the test for blank is included as insurance.
Jim