locked
mass url 301 RRS feed

  • Question

  • User2045693258 posted

    i know there are mutiple solutions to this but i cant see how they can solve my problem. i need to do a 301 redirect for lots of pages and rather than put my code into every page is there any way i can put it in a central file something like

    original page---page1.aspx

    301 redirect---page1new.aspx


    original page--page2.aspx

    301 redirect---page2new.aspx


    original page--pageofNews.aspx

    301 redirect---newsPage.aspx, etc,etc,etc


    I'm not changing domain, just changing the structure of the site to make it easier to manage

    Wednesday, October 28, 2009 6:25 AM

Answers

  • User2130758966 posted

    Yes you would use a urlrewriting library such as this one:


    Set it up by following the guide here:


    Then add rules like this to your web.config:

    <rewriter>
      <rewrite url="^/oldpage1.aspx" to="~/newpage1.aspx"/>
      <redirect url="^/oldpage2.aspx" to="~/newpage2.aspx"/>
    </rewriter>

    Notice two things about that code:

    1. The rewrite rule will point the old page at the new page but keep the old url, the redirect rule will send you from the old page to the new page
    2. The url attribute section is a regular epxression so you should use the ^ at the start to say "the url must start with this string", the to attribute can be a normal asp.net path so ~ notation is fine to use
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 9:17 AM

All replies

  • User2130758966 posted

    Yes you would use a urlrewriting library such as this one:


    Set it up by following the guide here:


    Then add rules like this to your web.config:

    <rewriter>
      <rewrite url="^/oldpage1.aspx" to="~/newpage1.aspx"/>
      <redirect url="^/oldpage2.aspx" to="~/newpage2.aspx"/>
    </rewriter>

    Notice two things about that code:

    1. The rewrite rule will point the old page at the new page but keep the old url, the redirect rule will send you from the old page to the new page
    2. The url attribute section is a regular epxression so you should use the ^ at the start to say "the url must start with this string", the to attribute can be a normal asp.net path so ~ notation is fine to use
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2009 9:17 AM
  • User2045693258 posted

    cheers harry, once again you've saved my bacon


    Wednesday, October 28, 2009 9:57 AM