Redirecting site or pages to a new domain or url aka 301 redirections

I learnt about 301 redirection when I moved my wordpress site from earlier domain to this new domain.

Htaccess redirect is better than the meta refresh or redirect tag because there is no delay as the browser reads the .htaccess file first. Here is how it works.

Go to your site’s root folder, download the .htaccess file to your local computer and edit it with a plain-text editor (ie. Notepad). If you are using FTP Client software and you don’t see any .htaccess file on your server, double check your setting and make sure you have turn on invisible / system files.

To Redirect Certain Page(s):

1
2
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

To Redirect Entire Site:

1
Redirect 301 / http://www.new-site.com/

You can also do this by placing an index.php file in the place where you had your earlier site. But its not the right way to do it and will reduce the response time of your site.

1
2
3
4
<?php
	header( "HTTP/1.1 301 Moved Permanently" );
	header( "Location: http://www.new-site.com" );
?>
Follow me

Abhishek Gupta

I am Abhishek from Lucknow (India). I have been working as a software engineer from last 6+ years, and its my passion to learn new things and implement them as a practice.
Follow me

Latest posts by Abhishek Gupta (see all)

Leave a Reply