Apache top-level domain jump
Toss the site also has a large six months, yesterday to listen to a colleague said our website through the domain name without www can also be accessed, with the WWW can also be accessed, the search engine is included in the situation is separately,
Originally has not cared about these details of things, such as our website is www.dt.com, without the WWW is dt.com, and not with the WWW is the real top-level domain name, with the WWW is a two-level domain name,
Now responsible for the search engine included the situation of colleagues asked us to let dt.com jump to www.dt.com, began to think of is to modify the http.conf file below Apache, not very understand the forwarding rules inside,
Found that the previously configured forwarding rules are a certain level two domain name jump to the specified IP, or pseudo static configuration, if the configuration top-level domain name jump to level two domain name.
Apache did not find a way, and think of a domain name management, domain name management inside the configuration of the domain name forwarding, it is estimated that the domain name provider in the toss, said temporarily does not provide forwarding function.
Search again today for the rewrite URL method of Apache, as follows:
Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host} ^dt\.com
Rewriterule ^ (. *) $ http://www.dt.com/$1 [r=permanent,l]
Here to determine whether the current server variable http_host is equal to dt.com, for the true rewrite, in accordance with the r=permanent for permanent redirection, L said
And immediately stop the rewrite operation and no longer apply other overriding rules
If you do not write r=permanent, the default is 302 temporary redirection, r=permanent or r=301, which is permanent redirection.
References: Http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteRule