The first method: direct to the band www without www
1, here I use mod_rewrite rewrite URL way to do, before friends remember to check whether your Apache has loaded the rewrite module. The module in the Apahce httpd.conf file.
650) this.width=650; "class=" Exp-image-default "alt=" Apache do 301 Redirect method "src=" Http://c.hiphotos.baidu.com/exp/w=500/ Sign=a1e09018fa1986184147ef847aec2e69/503d269759ee3d6d470092b241166d224e4ade80.jpg "style=" border:0px; "/>
2, if you have supported the rewrite, directly in the site configuration file you want to add the following code, pay attention to modify the domain name for the domain you want to do.
-----------------------------
Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host} ^php100.com
Rewriterule ^ (. *) $ http://www.php100.com/$1 [r=permanent,l]
----------------------------------------------------------------
3, here to determine whether the current server variable http_host is equal to php100.com, for the true rewrite, follow the r=permanent for permanent redirection, L represents and immediately stop the rewrite operation, and no longer apply other rewrite rules.
END
The second method: direct with www to the domain name without www
1, first I in Apache with this domain name set up two virtual host, a with WWW, a without.
2, then I will not take the correct resolution of the WWW to the corresponding website above, and then I will take the domain name resolution I to the WWW with the directory below a two-level directory, and then I put a index.php in this two-level directory, I use PHP code to do this 301.
3, the PHP code is as follows:
--------------------------------
<?php
Header ("http/1.1 301 Moved permanently");
Header ("location:http://xxx.com")//the domain name you want to target
?>
------------------------------------
4, so when the user access to the domain name with WWW, will visit this level two directory under the index.php,php will execute 301, will be the domain name jump transfer without WWW domain name, this jump time is very broken, the user does not feel out.
Precautions
These two methods apply only to Apache servers
This experience is done under Linux, Windows under the same code, only the configuration file modification and domain name resolution operation is not the same, please use WIN's friends to adjust their own
This article is from the "-it commune" blog, please be sure to keep this source http://guangpu.blog.51cto.com/3002132/1566363
Apache does 301 Redirect method