Forum Moderators: phranque
As strange as it may sound, i found one of our sites in google but with altered url.
instead of [demosite.com,...] the google had it as [%20demosite.com...]
So far i haven't been able to track from where the space (%20) came from.
Is it possible to have a rule in htaccess to redirect the spaced-url to the normal non-spaced url?
I have tried the following, but without any success
RewriteCond %{HTTP_HOST} ^%20www.demosite\.com
RewriteRule ^(.*)$ [demosite.com...] [R=permanent,L]
Any suggestions?
You can't (or should be able to) set-up a DNS A record for <space>www or %20www, nor would anybody be able to get to your web site with that URL even if you could.
Leaves the issue of URL rewriting moot.
This is a Google bug that should be reported to them. They shouldn't be indexing URLs with invalid domain names.
I can't say if a domain name with a space would actually resolve to your server, or if a redirect could be used to detect and fix the problem, but if it is possible, one of these three RewriteConds would be the way to do it:
RewriteCond %{HTTP_HOST} ^\%20www\.example\.com
RewriteCond %{HTTP_HOST} ^\ www\.example\.com
RewriteCond %{HTTP_HOST} !^www\.example\.com
However, even assuming that the space-domain request *is* resolved to your server, if the HTTP_HOST variable is "cleaned up" and the space removed by Apache prior to running this code, then it won't work.
Please post back and let us know what you discover.
Jim
You were both correct of course... none of the three solutions made any redirection to the correct url
I have tested the problem-solution with 3 browsers (IE 6.0.28, Opera 9.0 and Fireox 1.03) and only IE accepts the invalid url (both Opera and Firefox don't allow a user to visit an invalid url).
Also some nice findings about the domain redirections:
in the htaccess i have for quite some time (and tested in IE 5.5 the following rule
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
Now if i remove the rule and type just example.com in browser i get the following:
IE: no redirection whatsoever (correct since no rule exists)
Opera: no redirection whatsoever (correct since no rule exists)
Firefox: redirects to www.example.com!
Now if i put the rule back and type the same url i got the following:
IE: no redirection!
Opera: redirects to www.example.com
Firefox: redirects to www.example.com
Now i am pretty sure the rule worked for IE some months ago when i put it there. Seems some "IE security update" mess up something :)