How to properly implement a 301 redirect - To Implement a 301 Redirect is the best way for everyone who want to redirect an old website to a new address. (A Brief Definition Of 301 Redirect: A 301 redirect is a command used to tell the search engines that a page has permanently moved, and that you want them to index the new page and drop the old one from their index). You can use this 301 redirect in separate situations.
Condition are listed below?
If you want to modulate a URL structure change.
If you want to redirect an old website to a new address.
If you want to set up several domains pointing to one website.
If you want to apply only one version of your website (www. /Without - www)
So today I'm going to show you how you can easily set up a 301 redirect. Yes' it's very simple and you can do it with the help of some codes. Follow the below instruction to setup a 301 redirect.
How To Redirect A Single PHP Page?
If you want to redirect a single page to a new address simply enter the below code inside the index.php file.
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>
For PHP Canonical Redirect?
The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain. With the help of this below code your visitors will redirects http://askwithloud.com version to http://www.askwithloud.com.
<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>
How To Redirect Apache .htaccess Singe Page?
If you want to redirect apache .htaccess Singe Page then, you will need to create a file (named .htaccess) (It's not supporting on Windows-based hosting) and place it on the root directory of your website, then just add the below code to the file.
Redirect 301 /old/oldpage.htm /new/http://www.domain.com/newpage.htm
For Apache .htaccess Canonical Redirect?
Follow the same steps you did before in PHP Canonical redirect. however add the below code.
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
That's it! I hope you like this tutorial! Stay tuned for more cool tips and tricks! Thanks for reading @Prince
0 Comment to "Easy Way To Setup 301 Redirect"
Post a Comment