Using 301 Redirects To Fix 404 Page Not Found Errors

Once you have found all of your site's not found errors using SpringTrax, the next question is, naturally, how do I fix those 404 errors?

SpringTrax Recommendations

With SpringTrax, we give you detailed steps to help you fix your website's not found error pages. For instance, you might find we recommend redirecting a broken link to a non-broken link on your site.

SpringTrax Redirect Recommendations
SpringTrax's recommendations tell you which redirects to implement to fix 404 errors on your site.

Adding in the redirect means that anybody who attempts to reach that 404 error URL (in the screenshot above, "/login" is a broken link), will instead be taken to a working page on your site (in the screenshot above, /login.html). As a result, nobody will be able to reach that same 404 error again.

There are recommended steps we will take, but we'll tackle those in separate blog posts. For now, let's talk about the redirect as a way to fix 404 errors.

404 Error Fixes: Adding A Redirect

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.

Using the recommended redirect in the screenshot above, we need to redirect /login (the 404 error page) to /login.html (a working page on that website). There are many different 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 of those 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 http://builtwith.com/.) This file is located in the main directory (or root directory) of your website. 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 "examplesite.com").
  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 http://www.examplesite.com/login.html. For this URL, we do want to include the domain name (so, do include "examplesite.com").

That is it! Putting it all together, you would have a line in your .htaccess file that looks something like this:

redirect 301 /login http://www.examplesite.com/login.html

After saving your .htaccess file to your server, the next time you visit examplesite.com/login, you will be redirected to examplesite.com/login.html.

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, we'll use the second recommendation in the screenshot above: http://www.examplesite.com/calendar/634.html. With the broken link "calendar/634.html", we want to state our redirect path as: <location path="calendar/634.html"> Note that we don't inlcude examplesite.com (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 http://www.examplesite.com/calendar.html. 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 examplesite.com) we want to redirect to. That statement looks something like <httpRedirect enabled="true" destination="http://www.examplesite.com/calendar.html" />
  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="http://www.examplesite.com/calendar.html" 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">
   <system.webServer>
      <httpRedirect enabled="true" destination="http://www.examplesite.com/calendar.html" httpResponseStatus="Permanent" />
   </system.webServer>
</location>

After adding this to the web.config file, going to http://www.examplesite.com/calendar/634.html will redirect us to http://www.examplesite.com/calendar.html.

Need Help?

If you need help adding redirects to your website, just send us an email. We're happy to help you fix your website's 404 not found errors.

If you sign up for SpringTrax, we provide recommendations on how to fix your 404 errors, including what redirects to implement.



 

Share This Post


Add Comments

comments powered by Disqus

Are You Ready To Quit Losing Customers?

Sign Up Today To Find & Fix Every 404 Error On Your Website.


Sign Up Today

Starts at $19.99/month. 30 day money back guarantee. Cancel at any time.