Using 301 Redirects To Fix 404 Page Not Found Errors

You can think of a redirect like the online version of mail forwarding. If you move, you tell the post office to forward mail arriving at your old address to your new address instead. In the case of a redirect, you are telling your server to forward (or redirect) any requests made of a broken URL to a working URL instead. The way you tell your server to do this is by adjusting code on your server.

For example, let’s say we need to redirect /login (a 404 error page) to /login.html (a working page on that website). There are many ways to do this, and you should work with your web development team to find the right way to make this work on your server. Two of the more common ways of implementing a redirect are through an htaccess file and through a web.config file. Let’s take each one-by-one to see how exactly they work.

.htaccess Redirect

An .htaccess file is a control file for Apache servers. (You can find out what kind of server you are on by using a tool like This file is located in the main directory (or root directory) of your website (make sure to view hidden files). In this file, you can put a number of statements telling the server what to do.

  1. To create the statement in the .htaccess file, you want to first state that you are making a redirect with the statement redirect.
  2. Next, you want to define the type of redirect. In this case, we want to permanently fix the broken link, so the redirect type is 301(which is a server-code for “Moved Permanently”).
  3. Then you want to state the broken URL we want to redirect somewhere else. In our case, we are fixing the broken link of “/login”. So, we’ll want to state /login. Note that, this broken link shouldn’t include your website’s domain (so, no “”).
  4. Finally, you want to state what URL to redirect to. In our case, this is “/login.html”, which is the working page on this website. We’ll state this by adding For this URL, we do want to include the domain name (so, do include “”).

That is it! Putting it all together, you would have a line in your .htaccess file that looks something like this:
redirect 301 /login
After saving your .htaccess file to your server, the next time you visit, you will be redirected to

web.config Redirect

If you don’t have an Apache server, adding in the redirect via an .htaccess file won’t work. Another common method is adding in a redirect via a web.config file. Like the .htaccess file, a web.config is located in the main directory (or root directory) of your website. Also like an .htaccess file, you add a statement telling the server to redirect a certain URL. The redirect instructions go in between the <configuration> </configuration> tags.

  1. To create the statement in the web.config file, you will start by defining the path of the file you want to redirect (the broken link). For this example, let’s say that returns a 404 error. To prevent people from visitng “calendar/634.html” and receiving that error message, we want to redirect that URL to a working URL. To do that in the web.config file, we need to state our redirect path as: <location path=”calendar/634.html”>Note that we don’t inlcude (our domain) in this path definition.
  2. Next, we want to define our destination, which is where we want the broken link to redirect to. In our case, we want to redirect the broken link to This instruction is contained within an attribute of the httpRedirect tag. The attribute name is destination and the value is the full URL (including the domain we want to redirect to. That statement looks something like <httpRedirect enabled=”true” destination=”” />
  3. In the httpRedirect tag, we also want to add an attribute httpResponseStatus and set that attribute to “Permanent”. This indicates that this is a permanent solution to the broken link. The full httpRedirect tag statement looks like <httpRedirect enabled=”true” destination=”” httpResponseStatus=”Permanent” />
  4. Finally, we want to contain the httpRedirect tag within a <system.webServer> tag. The <system.webServer> tag ends up contained within the <location path=”calendar/634.html”> tag we defined in step 1.

Putting all of that together, we end up with a full statement that looks like this:
<location path="calendar/634.html">
<httpRedirect enabled="true" destination="" httpResponseStatus="Permanent" />

After adding this to the web.config file, going to will redirect us to

Need Help?

If you need help adding redirects to your website, please contact me. I’m happy to help you fix your website’s 404 not found errors.