Apache Configuration 301 Jump

Source: Internet
Author: User

We now have test and AAA in the visit to this discuz forum, then the two domain name pits will be divided into a primary and secondary, especially now search engine he will have a ranking weight, then the official language is called "PR", then the PR high and low will have an impact, the search engine can not distinguish between primary and secondary, So we now help the search engine to prioritize, this time we have a method called Jump: The domain name of the jump, access aaa.com jump to test.com, then I configured to edit the virtual host configuration file

[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

To configure a jump, jump using a module called rewrite module

<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{http_host} ^www.aaa.com$

Rewriterule ^/(. *) $ http://www.test.com/$1 [r=301,l]

</IfModule>

Let's take a look at the rewrite module, there is no load

[Email protected] ~]# apachectl-m

Loaded Modules:

Core_module (Static)

Authn_file_module (Static)

Authn_default_module (Static)

Authz_host_module (Static)

Authz_groupfile_module (Static)

Authz_user_module (Static)

Authz_default_module (Static)

Auth_basic_module (Static)

Include_module (Static)

Filter_module (Static)

Log_config_module (Static)

Env_module (Static)

Setenvif_module (Static)

Version_module (Static)

Mpm_prefork_module (Static)

Http_module (Static)

Mime_module (Static)

Status_module (Static)

Autoindex_module (Static)

Asis_module (Static)

Cgi_module (Static)

Negotiation_module (Static)

Dir_module (Static)

Actions_module (Static)

Userdir_module (Static)

Alias_module (Static)

So_module (Static)

Deflate_module (Shared)

Expires_module (Shared)

Rewrite_module (shared) Sharing module

Php5_module (Shared)

Syntax OK

We need to change the configuration:


Rewritecond%{http_host} ^www.aaa.com$ Jump Condition

Rewriterule ^ (. *) $ http://www.test.com/$1 [r=301,l] rule L: Indicates last end

^: With ..... Beginning

/(. *) is a representative of the www.test.com behind www.test.com/http_host

To mark the final jump to this www.test.com.

r=301 This 301 is the status code

Jumps are divided into two types: one is 301 permanent redirects, the search engine friendly

One is 302 temporary redirect

Our website domain jump must use 301, is very friendly to the search engine

Can be tested with curl

[Email protected] ~]# curl-x 192.168.140.100:80 Www.aaa.com-I

http/1.1 301 Moved Permanently

Date:mon, Dec 15:56:11 GMT

server:apache/2.2.31 (Unix) php/5.3.27

location:http://www.test.com//

content-type:text/html; Charset=iso-8859-1

You can specify an IP when testing,-I can see the status code

Sometimes we also encounter more than two domain names, AAA or BBB

<virtualhost *:80>

DocumentRoot "/data/www/"

ServerName www.test.com

Serveralias www.aaa.com

Serveralias www.bbb.com

# errorlog "Logs/dummy-host2.example.com-error_log"

# customlog "Logs/dummy-host2.example.com-access_log" common

<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{http_host} ^www.aaa.com$ [OR]

Rewritecond%{http_host} ^www.bbb.com$

Rewriterule ^/(. *) $ http://www.test.com/$1 [r=301,l]

</IfModule>

[or] means, without [or], that the two conditions exist simultaneously


This article is from the "Dream On the Ridge" blog, be sure to keep this source http://mengjunlinux.blog.51cto.com/10772888/1729809

Apache Configuration 301 Jump

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.