02-23-2017, 04:07 AM
Here are some common redirects that are used almost often my webmasters and site owners. So, decided to provide the codes of them.
PHP Single Page Redirect
You have to insert this code in index.php file.
PHP Canonical Redirect
This add or removes the 'www' prefix of your domain.
.htaccess Singe Page Redirect
Insert this code in your .htaccess file
.htaccess Canonical Redirect
PHP Single Page Redirect
You have to insert this code in index.php file.
Quote:<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: <!-- m --><a class="postlink" href="http://www.newdomain.com/page.html">http://www.newdomain.com/page.html</a><!-- m -->");
exit();
?>
PHP Canonical Redirect
This add or removes the 'www' prefix of your domain.
Quote:<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: <!-- m --><a class="postlink" href="http://www.'.$_SERVER">http://www.'.$_SERVER</a><!-- m -->['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>
.htaccess Singe Page Redirect
Insert this code in your .htaccess file
Quote:Redirect 301 /old/oldpage.htm /new/http://www.domain.com/newpage.htm
.htaccess Canonical Redirect
Quote:Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ <!-- m --><a class="postlink" href="http://www.domain.com/$1">http://www.domain.com/$1</a><!-- m --> [r=301,nc]