How to redirect 301 by rewriting URL
When you running a website, sometimes you will have visit requirement, like as use http://1.abc.com to visit http://www.abc.com/1, and you need to redirect setting of website visiting. The most efficient method in our platform is rewrite the URL. Below are some samples:
1.
Redirect domain.com to www.domain.com
Rewrite Engine On
Rewrite Cond %{HTTP_HOST} !^www.domain.com$ [NC]
Rewrite Rule ^(.*)$ http://www.domain.com/$1 [L,R=301]
2.
Redirect www.domain.com to domain.com
Rewrite Engine On
Rewrite Cond %{HTTP_HOST} !^domain.com$ [NC]
Rewrite Rule ^(.*)$ http://domain.com/$1 [L,R=301]
3.
Redirect olddomain.com to www.newdomain.com
Rewrite Engine On
Rewrite Cond %{HTTP_HOST} !olddomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
4.
Redirect olddomain.com to newdomain.com
Rewrite Engine On
Rewrite Base /
Rewrite Cond %{HTTP_HOST} !olddomain.com$ [NC]
Rewrite Rule ^(.*)$ http://newdomain.com/$1 [L,R=301]
5.
Redirect domain.com/file/file.php to otherdomain.com/otherfile/other.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$
Suggested Reading:
- What Operating System should I install on my server?(Views: 2107)
- What is a MySQL database?(Views: 2111)
- MySQL int (M) instruction(Views: 1746)
- MYSQL modify the password in several ways(Views: 1765)
- Points to remember Choosing between SSD and SAS Drives(Views: 1658)