Do you want to have your website automatically redirect to another site or specific page? (read on)
Redirects are fairly simple. BUT you need to know what type of file types you are using (php, asp, cfm, etc.) OR if your webhost uses to “cPanel” you can this without knowing code.(watch quick video) One important note to consider when doing this is to not only think about the redirect but how the search engines will treat the redirect. Most folks want to get (and keep) the best search results they can and implementing redirects can affect those search results. Google and the others look very carefully at redirects to make sure that their results point to valid content. How do implement correctly? “301 Redirects” (The 301 tells search engines that the page has *permanently* moved to a new location and keeps your search engine results in tact) There are other redirect types, but for this post, we’ll just deal with 301s.
So What Exactly Do I Need to Do To Correctly Redirect My Site??
Below are snippets of code (by script/file type) to place at the very top of your homepage: (These snippets are for those who are not using content management systems like WordPress. Most likely you’ll need to implement the redirect via .htaccess, either manually or via cPanel)
PHP Redirect
<?php
header( “HTTP/1.1 301 Moved Permanently” );
header( “location: https://www.thenewsite.com” );
?>
.NET Redirect
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”,”https://www.thenewsite.com”);
}
</script>
Ruby on Rails Redirect
def old_action
headers[“Status”] = “301 Moved Permanently”
redirect_to “https://www.thenewsite.com”
end
ASP Redirect
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”https://www.thenewsite.com”
%>
JSP Redirect
<%
response.setStatus(301);
response.setHeader( “Location”, “https://www.thenewsite.com” );
response.setHeader( “Connection”, “close” );
%>
PERL / CGI Redirect
$q = new CGI;
print $q->redirect(“https://www.thenewsite.com”);
.htaccess Redirect
You can also do an .htaccess redirect (copy and paste the code below into a new file as save as “.htaccess”) This single file, uploaded to the root directory of your website will redirect all directories and page files from your existing domain to the new domain.
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://www.thenewsite.com/$1 [R=301,L]
*Notes:
Replace the “www.thenewsite.com” in the above code with your actual domain name.
This works ONLY on Linux servers with the Apache Mod-Rewrite moduled enabled. (talk to your webhost to verify)
Plain HTML
*If for whatever reason (as a last resort) you can only redirect a flat html page, please do the folowing “Meta Refresh” (I mention this because Google doesn’t really like it) ;)
<html>
<head>
<meta http-equiv=”refresh” content=”0;URL=https://whatever.com”>
</head>
<body>
Create Redirects via Cpanel
(video courtesy of LearningCPanel)
[…] and I see folks getting virtually punished for not knowing about nor implementing this “redirect” […]