Apache Redirect (301) to new domain name

Source: Internet
Author: User

Apache under 301 redirect Code (because I'm using Windows 2003 + Apache so this article is only available to APACHE servers.) )

Create a new. htaccess file and enter the following (you need to turn on mod_rewrite):

1) Turn the domain name without www to the domain name with www

Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host} ^163.com [NC]
Rewriterule ^ (. *) $ http://www.163.com/$1 [l,r=301]

2) redirect to new domain

Options +followsymlinks
Rewriteengine on
Rewriterule ^ (. *) $ http://www.001.com/$1 [l,r=301]

3) Use regular 301 redirect for pseudo-static

Options +followsymlinks
Rewriteengine on
Rewriterule ^news-(. +) \.html$ news.php?id=$1

Turn the news.php?id=123 address to news-123.html.

Apache under vhosts.conf configuration 301 redirect

In order to implement URL normalization, SEO usually turn the domain name without www to the WWW domain name, vhosts.conf is configured as:

<virtualhost *:80>
ServerName www.001.com
Documentroot/home/fari001com
</VirtualHost>

<virtualhost *:80>
ServerName fari001.com
Redirectmatch permanent ^/(. *) http://www.001.com/$1
</VirtualHost>


Apache Redirect (301) to new domain name

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.