Hey all, I've got a question about IIS7 rewrite.
I'm wondering if there is a way to set conditions for re writing urls. I'm wanting to rewrite:
to become
http://www.domain.com/username/
I also have
http://www.domain.com/article.aspx http://www.domain.com/login.aspx
and I want those to become
The issue I'm having is that if I set up the rewrites for username the rewrites for article and login break.
I need to somehow exclude those from the username rewriting so that they can be handled on their own.
Here is my current code, im rewriting the usernames to /user/username at the moment:
<rewrite> <rules> <rule name="Rewrite user accounts2"> <match url="user/([_0-9a-z-]+)"/> <action type="Rewrite" url="user.aspx?id={R:1}"/> </rule> <rule name="Rewrite user accounts"> <match url="user/([_0-9a-z-]+)/"/> <action type="Rewrite" url="user.aspx?id={R:1}"/> </rule> </rules> </rewrite>
views:
71answers:
1
A:
If you add the article/login rule at the top and add stopProcessing="true" to it then you dont have to use conditions.
<rewrite>
<rules>
<rule name="Login" stopProcessing="true">
<match url="login/?"/>
<action type="Rewrite" url="login.aspx"/>
</rule>
<rule name="Article" stopProcessing="true">
<match url="article/?"/>
<action type="Rewrite" url="article.aspx"/>
</rule>
<rule name="Rewrite user accounts2" stopProcessing="true">
<match url="user/([_0-9a-z-]+)/?"/>
<action type="Rewrite" url="user.aspx?id={R:1}"/>
</rule>
</rules>
</rewrite>
PS. the questionmark makes the preceding character optional.
Fabian
2009-08-20 20:59:32
Thanks so much Fabian, just one more part to the question.Say I want to take away /user/ and just make the account domain.com/username/ how do I stop it conflicting with the login/article rewrites?Matt
bExplosion
2009-08-21 14:22:37
You're quite welcome :).You can just remove user/ from the match url in the example i wrote.So when its not login or article it will check "([_0-9a-z-]+)/?" and rewrite accordingly.
Fabian
2009-08-21 15:16:15