Apache does 301 Redirect method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.