BIOS,Windows, Linux, Software,Security, Domains, Web Hosting

How to Redirect Site to Another in Apache

If you want to change a new domain for your site, you may need to redirect the original site to a new one permanently. This tutorial will talk about 301 redirect, which can lead the user to the new site without few lost. Here assumed you want to redirect site A(www.a.com) to site B(www.b.com), and you are using a apache hosting, if your host is IIS, please refer to another article in my blog.

For apache hosting, it is very easy to redirect one site to another permanently using 301 redirect. Just add some codes in your .htaccess file which should be found in your root directory, if it does not existed, create a empty .htaccess instead. 

Steps of 301 redirect for a whole site

1. Download your .htaccess in site A with a FTP software.

2. Open the .htaccess with notepad.exe or wordpad.exe

3. Add these codes in .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.a.com$ [NC]
RewriteRule ^(.*)$ http://www.b.com/$1 [L,R=301]

4. Save .htaccess and upload it to the original directory, the old htaccess will be replaced.

5. Ok, type the site A url in the address bar, you will get http://www.b.com automatically. 

 

Samples 301 redirect for wordpress

Native .htaccess in the root:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
	
# END WordPress

Change to(Note: Please change the URL path to your own. ):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.a.com$ [NC]
RewriteRule ^(.*)$ http://www.b.com/$1 [L,R=301]
</IfModule>
	
# END WordPress

Related Articles

Comments(0)  

Leave a Reply

Subscribe to BootBeta Comments RSS feed to receive notification of latest comments posted.

Subscriptions

  • Enter Email Address:

Recent Post

Copyright@ 2010-2014 Bootbeta All Rights Reserved.
HooBlog Ver 1.5 Build 20140530