views:

16

answers:

1

How can I forward short-dom.com to long-domain.com ?

I keep seeing examples like:

RewriteCond %{HTTP_HOST} ^a\.com$ [NC]
RewriteRule ^(.*)$ http://www.a.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^b\.com$ [NC]
RewriteRule ^(.*)$ http://www.b.com/$1 [L,R=301]

But these don't allow me to specify my short domain (all combinations of it - with or without www.)...

A: 

In the examples in your question, the place you specify the domain is on the line that says RewriteCond.

For example, this condition

RewriteCond %{HTTP_HOST} ^old\.example\.com$ [NC]

will match if the host name in the http request (%{HTTP_HOST}) matches the regular expression that follows. Your examples will match "a.com" while mine will match "old.example.com".

The line that says RewriteRule will do the actual rewriting. In your example it will replace

http://a.com/anything

with

http://www.a.com/anything

by substituting the regular expression matched with a new URL.

^(.*)$ matches the entire request and $1 substitutes it in the new URL.

bmb