Preston
Preston

Reputation: 420

Web.Config 301 Redirect

I am trying to redirect a specific page from my old domain to a specific page on my new domain. The URLs look like the following:

http://blog.mysite.com/post/2012/05/hungry.aspx

to

http://mynewsite.com/hungry.aspx

I've looked to the Web.Config file to make this change, however the following code is not working:

<location path="post/2012/05/hungry.aspx">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://mynewsite.com/hungry.aspx" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>

When I visit my old blog page, it does no redirection and remains on the old blog page.

Am I missing something?

Upvotes: 0

Views: 5326

Answers (1)

Antonio Bakula
Antonio Bakula

Reputation: 20693

If http redirection is enabled on old server then you have to put new web config in folder post/2012/05/ with this content

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="true" destination="http://mynewsite.com/" httpResponseStatus="Permanent" />
    </system.webServer>
</configuration>

btw. if all other options fails you could simply do that using Response.Redirect from code behind.

Upvotes: 1

Related Questions