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] |