The “301 Permanent Redirect”
is the most efficient and search engine
friendly method for redirecting websites. You can use it in several situations,
including:
- to redirect an old website to a new address
- to setup several domains pointing to one website
- to enforce only one version of your website (www. or no-www)
- to harmonize a URL structure change
PHP
Single Page Redirect
<?php
header("HTTP/1.1
301 Moved Permanently");
header("Location:
http://www.newdomain.com/page.html");
exit();
?>
PHP Canonical Redirect
The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain. The code below redirects the visitors of the http://domain.com version to http://www.domain.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']);
}
Apache .htaccess Singe Page Redirect
Redirect
301 /old/oldpage.htm
/new/http://www.domain.com/newpage.htm
?>
Apache .htaccess Canonical Redirect
Options
+FollowSymlinks
RewriteEngine
on
rewritecond
%{http_host} ^domain.com [nc]
rewriterule
^(.*)$ http://www.domain.com/$1 [r=301,nc]
ASP Single Page Redirect
This redirect method is used with the Active Server Pages platform.
<%
Response.Status="301
Moved Permanently"
Response.AddHeader='Location','http://www.new-url.com/'
%>
ASP Canonical Redirect
The Canonical Redirect with ASP must be located in a script that is executed in every page on the server before the page content starts.
<%
If
InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
Response.Status="301
Moved Permanently"
Response.AddHeader
"Location","http://www."
&
Request.ServerVariables("HTTP_HOST")
&
Request.ServerVariables("SCRIPT_NAME")
End
if
%>
I’m impressed, I must say. Truly rarely do I encounter a weblog that’s both educative and entertaining, and without a doubt, you might have hit the nail about the head. Your concept is outstanding; the problem is something which too few people are speaking intelligently about. We are happy which i found this around my look for something regarding this. jhhdhasdsfg.host
ReplyDeleteHi there, I discovered your website by way of Google even as looking for a related subject, your site got here up, it appears great. I have bookmarked it in my google bookmarks. jhhdhasdsfg.host
ReplyDelete