• About Us
  • Services
  • Case Studies
  • Blog
  • Contact Us
  • Canonical domain 301 redirects

    During the re-design of this website I have ensured that a canonical form of domain listing is not indexed by redirecting kevingibbons.co.uk to www.kevingibbons.co.uk. This is important as a website can be penalised if it has duplicate content appearing in the SERPs. The best way of redirecting the canonical url is via a 301 redirect which lets the search engines know that the page has been permanently moved. This is generally setup via server settings such as .htaccess or an IIS redirect but as my hosting account does not allow this I have had to hardcode this into the site. I’ve added the code to redirect to the www subdomain below using .htaccess and both ASP and PHP.

    ASP Subdomain Redirect Code:
    <%
    If Request.ServerVariables(“HTTP_HOST”) = “mysite.com” Then
    Response.Status=”301 Moved Permanently”
    Response.AddHeader “Location”, “http://www.mysite.com” & Request.ServerVariables(“PATH_INFO”)
    End If
    %>

    PHP 301 Subdomain Redirect Code:
    <?
    if ( strtolower($_SERVER['HTTP_HOST']) == “mysite.com” )
    {
    header(“HTTP/1.1 301 Moved Permanently”);
    header(“Location: http://www.mysite.com” . $_SERVER["REQUEST_URI"]);
    exit();
    }
    ?>

    .htaccess Apache mod_rewrite 301 redirection:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mysite.com [nc]
    RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

    If you need to redirect an individual URL using .htaccess you should use the following line of code:
    Redirect 301 /filename http://www.domain.com

    Microsoft IIS 6.0 301 redirects
    Via Microsoft Support:

    To redirect browser requests to another folder or Web site:
    1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
    2. Click to expand * server name, where server name is the name of the server.
    3. Right-click either the Web site or the folder that you want to redirect, and then click Properties.
    4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory
    5. Under When connecting to this resource, the content should come from, click A redirection to a URL.
    6. Type the URL of the destination folder or Web site in the Redirect to box.

    For example, to redirect all requests for files in the Products folder to the NewProducts folder, type /NewProducts. To redirect all requests for files located at www.mycompany.com/products to sales.mycompany.com/newproducts, type http://sales.mycompany.com/newproducts.
    7. Click OK.

    ABOUT THE AUTHOR

    2 Responses to “Canonical domain 301 redirects”

    1. [...] recommend, but I felt it would be best to offer the SEO blog as part of the new website. Using a 301 redirect from the old domain to let the search engines know the page has been permanently [...]

    2. [...] redirects mod_rewrite, 301/401 Redirects & Optimizing Apache Canocial domain 301 redirects 5 htaccess Tricks Every Webmaster Should Know Apache Redirect [...]

    Leave a Reply