I rebuilt my old site. There was a subdomain to that old site: forum.example.com
. Now, it does not exist anymore. A person who accesses my site using forum.example.com
should be redirected to example.com
.
My .htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
If the host is not example.com
, redirect to example.com
. Shouldn't forum.example.com
fit in the condition?
Now for the optional part of the question, if someone could explain to me the rule above, it would be great.
Here's what I understand in the above rule:
If the host is NOT example.com
(!^example.com$
)
redirect to http://example.com
.
What I don't understand is the first part of the rule regex: ^(.*)$
, and then the reference to it ($1
). How come matching everything can be put as the requested file path? Wouldn't it do something like this?
http://example.com/http://www.example.com/[requested file]