TL;DR: If you’re going to move to a new URL, fill out my templates and put them at the old one to make damn sure other people’s links don’t break....
TL;DR: If you’re going to move to a new URL, fill out my templates and put them at the old one to make damn sure other people’s links don’t break.
Yesterday, I finally found a use for the root http://ssokolow.com domain… I delegated it to GitHub to shorten and professionalize URLs for my projects. (eg. http://ssokolow.com/quicktile )
…but that meant that I could no longer use .htaccess to set up permanent redirects on URLs like http://www.ssokolow.com/ContactMe .
After a little research, it turns out that GitHub Pages doesn’t seem to have a method of declaring HTTP redirects… but Google and Yahoo will treat no-delay meta redirects as if they were HTTP 301.
Here’s what I came up with for a general, thorough way to ensure the least chance of broken links. (including .htaccess in case I switch hosting in the future) The example assumes you’re moving a whole domain (eg. from SourceForge to GitHub ), but it applies equally well to specific URLs within a domain.
(Also, don’t forget to use the change-of-address notification feature in Yahoo and Google Webmaster Tools)
# The proper way to HTTP Redirect... but not all hosts listen to .htaccess (eg. GitHub Pages)
# Some hosts also provide a special redirect option in their hosting controls.
RedirectPermanent / http://www.newsite.com/
# Probably never used, but just to be thorough.
ErrorDocument 404 /404.html<!DOCTYPE html>
<html>
<head>
<!--
Custom 404 page. (GitHub Pages version)
This will provide a last-ditch protection against broken links for actual users.
However, search engines won't recognize it as a redirect. Hence why index.html is necessary.
IMPORTANT: You should also activate your old site in Yahoo and Google Webmaster Tools.
That will allow you to file a change of address notification in their search indexes
for all pages within your domain.
-->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var NEW_HOST = 'www.newsite.com';
location.replace(location.protocol + '//' + NEW_HOST + location.pathname + location.search + location.hash);
</script>
</head>
<body>
<noscript><p>This content has moved. Please replace the <code>http://www.oldsite.com/</code> portion of
the address in your address bar with <code>http://www.newsite.com/</code>.</p></noscript>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<!--
The less-than-ideal way to redirect that relies on the browser rather than the server.
Requires a browser or other compatible User Agent and only covers the site root,
but Google and Yahoo treat it as equivalent to a proper HTTP 301 redirect.
Source: http://sebastians-pamphlets.com/google-and-yahoo-treat-undelayed-meta-refresh-as-301-redirect/
-->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0;url=http://www.newsite.com/" />
</head>
<body>
<p>This content has moved to <a href="http://www.newsite.com/">http://www.newsite.com/</a>. Attempting to automatically redirect you.</p>
</body>
</html>
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License .
Thanks for the step by step process. This really helps! I have been lost for a while now.