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 are the advantage of using a dedicated server?(Views: 2976)
- Points to remember Choosing between SSD and SAS Drives(Views: 2149)
- What is a MySQL database?(Views: 2604)
- LAMP configuration example(Views: 5004)
- National domain suffix(Views: 3812)


United States
Canada
Mexico
Panama
Belize
Greenland
Grenada
Puerto Rico
Hong Kong SAR China
Singapore
South Korea
Indonesia
Japan
Malaysia
Pakistan
Turkey
France
Germany
United Kingdom
Netherlands
Czech Republic
Italy
Luxembourg
Switzerland
Brazil
Argentina
Bolivia
Chile
Colombia
Ecuador
French Guiana
Paraguay
Australia
New Zealand
Cook Islands
Fiji
Pitcairn Islands
Solomon Islands
Tonga
Tuvalu