Forum Moderators: phranque

Message Too Old, No Replies

Rewrite hyphenated domains

         

Habtom

6:35 am on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have always used this for non-hyphenated domains, but for hyphenated domains it doesn't quite do it.

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.my-domain\.com [NC]
RewriteRule ^(.*)$ [my-domain.com...] [L,R=301]
ErrorDocument 404 /dyn/not_found.htm

Any ideas why?

jdMorgan

2:06 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code will redirect anything that does not start with "www.my-domain.com" to "www.my-domain.com".

As such, there is nothing "wrong" with it, and there is no reason it shouldn't work for any requested hostname regardless of hyphenation.

I'd look for problems outside of this code.

This code could be improved (a little) by modifying the RewriteCond to


RewriteCond %{HTTP_HOST} !^www\.my-domain\.com$

This requires an exact match -- in other words, it requires that the requested hostname be "exactly right," and therefore would redirect if the hostname casing was incorrect, if an FQDN was requested, or if a port number was appended, and is the recommended implementation to eliminate duplicate content. However, it won't affect the problem you report here, since it has nothing to do with whether hyphenated domains are redirected or not.

Do be sure to completely flush (delete) your browser cache before testing any new server-side code. Otherwise, your browser will show you previously-cached pages and server responses, confusing your test results.

Jim

Habtom

4:52 am on Aug 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim, thank you. It is working now.

The error log was showing this

Invalid command '\xef\xbb\xbfOptions'

In one of your posts, you mentioned this happens when a file is corrupted and recreating the file did the trick.

jdMorgan

2:54 pm on Aug 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow! -- Looks like a UTF character-encoding flag or something. Be sure you're using a plain-text editor to create and edit config files.

Jim