Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite with caps

rewriting domain with word case

         

8PDesign

7:40 pm on Dec 1, 2009 (gmt 0)

10+ Year Member



hi,
I would like mod_rewrite to rewrite my domain URL with the proper case, the way I like it displayed.

so from: ^mYdoMAin.com$ #Ignore case here
to: http://www.MyDomain.com/$1 #rewrite the domain part this way

But I can't seem to get it to work this way:

RewriteCond %{HTTP_HOST} ^mYdoMAin.com$ [nc]
RewriteRule ^(.*)$ http://www.MyDomain.com/$1 [r=301,C]

thanks in advance for your help!

[edited by: bill at 1:58 am (utc) on Dec. 2, 2009]
[edit reason] unlink example [/edit]

physics

7:52 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you want to redirect _all_ versions of your domain that don't look like MyDomain.com (including mydomain.com) to MyDomain.com?
This may be a bad idea for SEO reasons - you'll be redirecting the bots that navigate to your site with mydomain.com to MyDomain.com and there's some possibility that redirects can affect your rankings.

The problem with your example above I think is that it'll cause an infinite loop. You're matching mydomain.com with no case, so MyDomain.com matches. You need to match NOT www.MyDomain.com or NOT MyDomain.com.
I think this will work (untested)


RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?MyDomain\.com$
RewriteRule (.*) http://www.MyDomain.com/$1 [R=301,L]

[edited by: bill at 12:54 am (utc) on Dec. 2, 2009]
[edit reason] unlinked example [/edit]

8PDesign

8:08 pm on Dec 1, 2009 (gmt 0)

10+ Year Member



hi Physics, it does not work, seems to do a redirect loop.

Do you really think redirecting would fuss up the bots?!

thanks!

physics

8:38 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, not sure why that would happen here.
Are you sure you used "MyDomain.com" (with CamelCase) on both the RewriteCond and RewriteRule lines?
Here's the breakdown of the regex

! # NOT
^ # match beginning
(www\.)? # with or without www.
MyDomain\.com # match the exact casing MyDomain.com
$ # match end

Unfortunately I can't test right now but maybe you can debug using this as a reference:

[addedbytes.com...]

physics

8:42 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's some discussion on the 301 effect on rankings here [webmasterworld.com].
Honestly I don't know if it will hurt you - but most of the links you get will probably be of the form
http://www.mydomain.com/
and every time someone clicks or a bot visits that link they'll be 301'd to
http://www.MyDomain.com/

In a world where the engines have enough trouble with canonical www vs non-www domains why complicate things more?

[edited by: bill at 12:56 am (utc) on Dec. 2, 2009]
[edit reason] unlink example [/edit]

jdMorgan

10:07 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Browsers send domains as all-lowercase, so this redirect isn't going to work with any modern browser. The only reason to even consider case in incoming requests hostnames is for badly-coded robots (and malicious ones).

Sorry 8P, but you're up against the HTTP/1.1 specification here... :(

Jim

swa66

10:41 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The host part (FQDN) in a URL is case insensitive per the ruling RFCs. The rest of the URL after it is not case insensitive (not supposed to , till you run into software that breaks that rule like IIS)

physics

10:56 pm on Dec 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's just as well I guess given that it might be a bad idea anyway for the reasons discussed above...