My weekend project is to convert my old company website (koberleinstudios.com) into my personal site (markkoberlein.com). A while ago I posted about doing this along with changing the company name to Code.Paint. Well, it's finally happening. More about Code.Paint later, but I wanted to share something that's pretty important when you are moving a website or blog to a new domain.
When you are moving a blog or website to a new domain and the content (URLs) doesn't change, you need to make sure that you add redirects for the old domain name.
For example, because I'm moving koberleinstudios.com to markkoberlein.com I need to move the blog which used to default to markkoberlein.com and move it to blog.markkoberlein.com. Once I do this I need to make sure that if someone tries to view the http://markkoberlein.com/jamochatini-recipe blog post they are redirected to http://blog.markkoberlein.com/jamochatini-recipe.
This is very important SEO because all the links that Google knows about are going to your old domain until you tell Google that they have changed. If you don't have redirects in place than the user may receive an HTTP 404 error which is bad for usability.
In Django, this is easily accomplished by using the HttpResponsePermanentRedirect in the urls.py file.
#code from urls.py
from django.http import HttpResponsePermanentRedirect
urlpatterns = patterns('',
('^jamochatini-recipe$',lambda request: HttpResponsePermanentRedirect('http://blog.markkoberlein.com/jamochatini-recipe')),
)The HttpResponsePermanentRedirect is really nice because it will do permanent redirect (HTTP status code 301) which will tell search engines that the page has been moved and they should update the link on their end.
<style>
a {
background-color: #4652cc;
border: 1px solid #4652cc;
color:#ffffff;
padding:4px;
font-size:93%;
text-decoration:none;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius:5px;
}
</style>On Friday, a pretty big security vulnerability was disclosed that affects all ASP.NET applications and websites if the customErrors is set to Off or RemoteOnly in the web.config and you are not redirecting to a static error page for all your errors.
Scott Guthrie has a good post about this issue and the following workaround:
Enabling the Workaround on ASP.NET V1.0 to V3.5
If you are using ASP.NET 1.0, ASP.NET 1.1, ASP.NET 2.0, or ASP.NET 3.5 then you should follow the below steps to enable <customErrors> and map all errors to a single error page:
1) Edit your ASP.NET Application’s root Web.Config file. If the file doesn’t exist, then create one in the root directory of the application.
2) Create or modify the <customErrors> section of the web.config file to have the below settings:
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="~/error.html" />
</system.web>
</configuration>3) You can then add an error.html file to your application that contains an appropriate error page of your choosing (containing whatever content you like). This file will be displayed anytime an error occurs within the web application.
Notes: The important things to note above is that customErrors is set to “on”, and that all errors are handled by the defaultRedirect error page. There are not any per-status code error pages defined – which means that there are no <error> sub-elements within the <customErrors> section. This avoids an attacker being able to differentiate why an error occurred on the server, and prevents information disclosure.
Enabling the Workaround on ASP.NET V3.5 SP1 and ASP.NET 4.0
If you are using ASP.NET 3.5 SP1 or ASP.NET 4.0 then you should follow the below steps to enable <customErrors> and map all errors to a single error page:
1) Edit your ASP.NET Application’s root Web.Config file. If the file doesn’t exist, then create one in the root directory of the application.
2) Create or modify the <customErrors> section of the web.config file to have the below settings. Note the use of redirectMode=”ResponseRewrite” with .NET 3.5 SP1 and .NET 4.0:
<configuration>
<system.web>
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/error.aspx" />
</system.web>
</configuration>3) You can then add an Error.aspx to your application that contains an appropriate error page of your choosing (containing whatever content you like). This file will be displayed anytime an error occurs within the web application.
4) We recommend adding the below code to the Page_Load() server event handler within the Error.aspx file to add a random, small sleep delay. This will help to further obfuscate errors.
VB Version
Below is a VB version of an Error.aspx file that you can use, and which has a random, small sleep delay in it. You do not need to compile this into an application – you can optionally just save this Error.aspx file into the application directory on your web-server:
<%@ Page Language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
Sub Page_Load()
Dim delay As Byte() = New Byte(0) {}
Dim prng As RandomNumberGenerator = New RNGCryptoServiceProvider()
prng.GetBytes(delay)
Thread.Sleep(CType(delay(0), Integer))
Dim disposable As IDisposable = TryCast(prng, IDisposable)
If Not disposable Is Nothing Then
disposable.Dispose()
End If
End Sub
</script>
<html>
<head runat="server">
<title>Error</title>
</head>
<body>
<div>
Sorry - an error occured
</div>
</body>
</html>C# Version
Below is a C# version of an Error.aspx file that you can use, and which has a random, small sleep delay in it. You do not need to compile this into an application – you can optionally just save it into the application directory on your web-server:
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Security.Cryptography" %>
<%@ Import Namespace="System.Threading" %>
<script runat="server">
void Page_Load() {
byte[] delay = new byte[1];
RandomNumberGenerator prng = new RNGCryptoServiceProvider();
prng.GetBytes(delay);
Thread.Sleep((int)delay[0]);
IDisposable disposable = prng as IDisposable;
if (disposable != null) { disposable.Dispose(); }
}
</script>
<html>
<head runat="server">
<title>Error</title>
</head>
<body>
<div>
An error occurred while processing your request.
</div>
</body>
</html>