A summary of the implementation of Htaccess 301 redirection in Linux systems.

Source: Internet
Author: User

Be sure to back up the. htaccess file in the corresponding directory before you set 301 redirection. htaccess 301 Turn settings are limited to Linux hosts and need to support the virtual host, the last time you tried redirecting domain.com to www.domain.com, it really took effect immediately.

1. redirect domain.com to www.domain.com

This redirect is designed to make the domain name unique, is the website SEO must do, the back redirects www.domain.com to domain.com is also for the same reason, but the form is different. Open the. htaccess file and add the following rules. (The following rule is for the primary domain name, and the subdomain is to be modified)

The code is as follows Copy Code

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

2. redirect www.domain.com to domain.com

The code is as follows Copy Code

Rewriteengine on
Rewritecond%{http_host}!^domain.com$ [NC]
Rewriterule ^ (. *) $ http://domain.com/$1 [l,r=301]

3. REDIRECT olddomain.com to www.newdomain.com

The code is as follows Copy Code

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

4. redirect olddomain.com to newdomain.com

The code is as follows Copy Code

Rewriteengine on
Rewritebase/
Rewritecond%{http_host}!olddomain.com$ [NC]
Rewriterule ^ (. *) $ http://newdomain.com/$1 [l,r=301]

5. redirect domain.com/file/file.php to otherdomain.com/otherfile/other.php

The code is as follows Copy Code

Rewritecond%{http_host} ^www.domain.com$
Rewriterule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [r=301,l]

If it is a win host, see if your host supports redirection. If supported, your name file is: Httpd.ini, the code is:

  code is as follows copy code

[Isapi_ Rewrite]
Cacheclockrate 3600
Repeatlimit
Rewriteengine on
Rewritecond Host: ^nantongzufang.com$
R Ewriterule (. *) http://www.nantongzufang.com$1 [i,r]

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.