Forum Moderators: phranque

Message Too Old, No Replies

error in url.

can it be fixed with htaccess?

         

omoutop

1:58 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First of all, good day to all.

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?

jtara

3:03 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's impossible to fix this, because space characters are not allowed in domain names. Nor is the % character.

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.

jdMorgan

5:06 pm on Oct 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed, it's not possible to set up a DNS record for <space>www.example.com, but it is possible to set up a wild-card DNS record that might accept a space as a a match.

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

The first two examples include the "\" required to escape the special mod_rewrite meaning of "%" and space characters, while the third will redirect any domain not equal to "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

omoutop

6:31 am on Oct 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks for the info both of you.

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 :)