Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

URL Rewriting with .net

  • 17-09-2009 09:31PM
    #1
    Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭


    Hi,

    I've developed a web application that utilises UrlReWrite.Net to allow me to use clean SEO URLs. This works great on my local machine, but not on the web server.

    I contacted my web host and they've informed me that my application is hosted on a server using IIS 7, and this has a URL rewriting component provided by M$. I've searched for info on this but the only method of creating them I can find is through a UI within IIS that writes the rules to the web config.
    <rewrite>
      <rules>
        <rule name="Rewrite to article.aspx">
          <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
          <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
        </rule>
      </rules>
    </rewrite>
    

    When I add these to my web config it breaks the web app so I think I'm putting them in the wrong place. I've tried system.web and in the root but its still the same.

    Anyone know where exactly in web.config I need to put them?

    Thanks in advance :)


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Rewrite to article.aspx">
              <match url="^article/([0-9]+)/([_0-9a-z-]+)"/>
              <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    There you go :)


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Ginger wrote: »
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Rewrite to article.aspx">
              <match url="^article/([0-9]+)/([_0-9a-z-]+)"/>
              <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}"/>
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    There you go :)

    You're a gentleman Ginger, thanks very much! :)


  • Moderators, Science, Health & Environment Moderators Posts: 9,220 Mod ✭✭✭✭mewso


    Just re. what your host told you they may have been referring to the fact that IIS7 handles routing without wildcards. i.e. since asp.net 3.5 we have routing which allows us to use friendly urls in a much easier way than before. Asp.net MVC uses it but it is not exclusive to MVC. If you are hosting on IIS7 you owe it to yourself to check out routing - http://msdn.microsoft.com/en-us/library/cc668201.aspx.


Advertisement