301 redirect Configuration Code _linux in Apache

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

1 Change the domain name without www to the domain name with www
Copy Code code as follows:

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

2 Redirect to new domain
Copy Code code as follows:

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

3) using regular 301 redirects to achieve pseudo static
Copy Code code as follows:

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

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

Apache configuration 301 redirect in Lower vhosts.conf

In order to achieve URL normalization, SEO will usually change the domain name without www to the WWW domain name, vhosts.conf is configured as:
Copy Code code as follows:

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

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

Apache In addition to the above 2 methods, there are other configuration methods and optional parameters, it is recommended to read the Apache document.

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.