Apache Rewrite set multiple domain 301 to jump to the main domain name method _linux

Source: Internet
Author: User

If the site has more than one domain name, but do not want to disperse the weight, you can open rewrite settings, the number of domain names are 301 to jump to the main domain name, the specific code is as follows:

Rewriteengine
on Rewritecond%{http_host} ^mituxiu.com [Nc,or]
rewritecond%{http_host} ^www.mituxiu.com [NC, OR]
rewritecond%{http_host} ^metooshow.com [NC]
rewriterule ^ (. *) $ http://www.metooshow.com/$1 [l,r=301]

Where www.metooshow.com for the final hope that the domain name, and mituxiu.com, www.mituxiu.com and metooshow.com are expected to be 301 of the domain name jump. (Sub-domain name in the calculation of the weight of the time is also considered to be a separate new domain name, so this method can also be used without the WWW domain name and the domain name with the WWW jump) where or the meaning of "or", you can continue to add more domain names.

The configuration code can be written in httpd.conf, or written in the. htaccess file, if it is a WordPress user, when modifying the. htaccess file, remember to write the configuration code in the # BEGIN WordPress and # End WordPress, Otherwise it will be overwritten when the WordPress settings are set.

Resolution of question mark matching problem
Here's an example ... The company's Web site revision needs to be included in the page 301 to the new address, in the write Apache rewrite an address how can not be. Code:

/index.php/index/supply.html?cid=101000
= "
/sell/list-101000.html

Later realized that the problem may be caused by the question mark, check the data found that there is indeed a question mark caused by the revised resolution, the code is as follows:

 Rewritecond%{query_string} ^cid= (. +) $
 rewriterule ^/index.php/index/supply\.html$/sell/list-%1.html? [R=301,l]

Description
Rewriterule pattern does not process the query characters following the question mark at the time of the match, and requires the rewritecond instruction of a%{query_string} variable.

A question that requires an idea:
1, in the new address/sell/list-%1.html need to use the% plus ordinal to obtain rewritecond configuration of the corresponding parameter content, rather than the usual $ (matching rewriterule content)
2, the new address/sell/list-%1.html you need to add a question mark in the tail to end the query string, otherwise there will be/sell/list-1000.html?cid=1000 situation.

Official explanation
Pattern does not match according to the query string. To achieve this, you must use a rewritecond instruction with%{query_string} variables. Of course, you can also create a URL that contains a query string in the replacement string: Use a question mark in the replacement string to indicate that the part that follows should be injected back into the query_string. To delete an existing request string, you can use a question mark to terminate the replacement string. To combine the old and new query strings, use the [QSA] flag.

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.