How to Implement Apache 301 redirection

Source: Internet
Author: User

We know that apache has several places to implement virtual host configuration, but to implement 301 redirection, we know that there are at least three places to implement, vhosts. conf, httped. conf ,. in the htaccess file, the following describes the configuration method.

Create a. htaccess file // you can use windows cmd or a text editor.

301 the redirection code is as follows:

The Code is as follows: Copy code

RewriteEngine on

RewriteCond % {http_host} ^ abc.com [NC]

RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301, L]

RewriteCond % {http_host} ^ www.abc.com [NC]

RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301, L]

You can define multiple entries to achieve multiple jumps at the same time.

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:

The Code is as follows: Copy code

<VirtualHost *: 80>
ServerName www. Domain Name. com
DocumentRoot/home/fari001Com
</VirtualHost>

<VirtualHost *: 80>
ServerName domain name 1.com
RedirectMatch permanent ^/(. *) http: // www. Domain Name. com/$1
</VirtualHost>

In Apache, besides the above two methods, there are other configuration methods and optional parameters.

Related Article

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.