Configuration code for 301 redirection in Apache

Source: Internet
Author: User

Create a new. htaccess file and enter the following content (mod_rewrite must be enabled ):

1) switch the domain name without WWW to the domain name with WWWCopy codeThe Code is as follows: Options + FollowSymLinks
RewriteEngine on
RewriteCond % {HTTP_HOST} ^ jb51.net [NC]
RewriteRule ^ (. *) $ http://www.jb51.net/#1 [L, R = 301]

2) redirect to a new domain nameCopy codeThe Code is as follows: Options + FollowSymLinks
RewriteEngine on
RewriteRule ^ (. *) $ http://www.baidu.com/#1 [L, R = 301]

3) use regular expressions for 301 redirection to achieve pseudo-staticCopy codeThe Code is as follows: Options + FollowSymLinks
RewriteEngine on
RewriteRule ^ news-(. +) \. html $ news. php? Id = $1

Add news. php? Ids0123the address is directed to news-123.html.

Configure 301 redirection in vhosts. conf in Apache

To achieve URL standardization, SEO usually redirects a domain name without WWW to a domain name with WWW. The configuration in vhosts. conf is as follows:Copy codeThe Code is 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>

In addition to the preceding two methods in Apache, there are other configuration methods and optional parameters. We recommend that you read the Apache documentation.

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.