Sunday, March 18, 2012

Redirect using your web.config file

When I built a website for one of my course assignments, I initially put it in a subfolder on my server (because I was having some trouble with creating a subdomain at the time). Later, when the problems with the subdomains were fixed, I wanted my old location to redirect to the new location I had just created. If you are using a Windows server, you can do this with your web.config file.  (Apache servers would use a .htaccess file.)

Problem: Need to redirect old website to the new website.

Impact: Users will see the old page or, worse, will get fed up with having to manually go to another website. This will also impact search engine rankings.

Solution:
For this redirection, you will need to edit the web.config file in your old location because you want anyone browsing to the old location to go to the new one. Within your <configuration> tags, you'll need the <system.webServer> tags. Note that this is not the <system.web> tag. If you don't have this tag already in your web.config file, just put it in.

Now you'll need to type in something like the lines below:

<system.webServer>
   <httpRedirect enabled="true" destination="your_new_url" httpResponseStatus="Permanent" />
</system.webServer>

Notice that the httpResponseStatus is "Permanent" meaning that this redirection is permanent and that the URL given is the new URL. So now, when you go to your old URL, you will automatically be redirected to your new URL, which you specified in as the destination value above.

0 comments:

Post a Comment