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
In order to redirect a static page to a new address simply enter the code below inside the index.php file.
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.yournewdomain.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
In order to use this method you will need to create a file named .htaccess (not supported by Windows-based hosting) and place it on the root directory of your website, then just add the code below to the file.
Redirect 301 /old/oldpage.htm /new/http://www.domain.com/newpage.htm
Apache .htaccess Canonical Redirect
Follow the same steps as before but insert the code below instead (it will redirect all the visitors accessing http://domain.com to http://www.domain.com)
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
%>
Please subscribe, leave a comment, follow this blog and share this article with your friends and colleagues.
by: http://kedirizone.blogspot.com
1 comments:
Hi there, always i used to check blog posts here in the early
hours in the dawn, for the reason that i enjoy to learn more and more.
Here is my blog - exercises to jump higher exercises to improve vertical exercises to improve vertical jump exercises to improve vertical leap exercises to increase vertical exercises to increase vertical jump exercises to increase vertical leap exercises for vertical exercises for vertical jump exercises for vertical leap workouts to jump higher workouts to improve vertical workouts to improve vertical jump workouts to improve vertical leap workouts to increase vertical workouts to increase vertical jump workouts to increase vertical leap workouts for vertical workouts for vertical jump workouts for vertical leap vertical jump exercises vertical leap exercises vertical jump workouts vertical leap workouts
Post a Comment