Search code examples
iisurl-rewritingisapi

Can someone help with a rewrite rule for IIS?


I am using Helicon ISAPI_Rewrite and have entered the following Rewrite Rule:

RewriteRule /([^/?.]+) /MemberPages/OrderSupplies.aspx\?Name=$1 [NC,L]

However, I have little regex knowledge, and this rule almost works. However, here is my situation:

I want my visitors to be able to enter the following on the URL:

http://www.somedomain.com/UserName

and when they do, they get redirected to:

http://www.somedomain.com/MemberPages/OrderSupplies.aspx

The above rule, works, but I do not want the rule to fire if the UserName is a file.

For example the rule should NOT fire if the following is entered:

http://www.somedomain.com/Default.aspx  
http://www.somedomain.com/login.aspx  
http://www.somedomain.com/otherpage.aspx  

The rule above strips out the '.' but I want to ignore any filenames, or any text with a '.'.


Solution

  • I came up with the following:

    RewriteEngine On
    RewriteRule ^([^/?.]+)$ MemberPages/OrderSupplies.aspx?Name=$1 [NC,L]
    

    I'm not sure if you can specify the preceding / after the hostname or not in mod_rewrite. Also, you don't need to escape the ? in the replace string from what I know. But in any case if that doesn't work, try it the way you had it:

    RewriteEngine On
    RewriteRule ^([^/?.]+)$ /MemberPages/OrderSupplies.aspx\?Name=$1 [NC,L]
    

    So the general ^([^/?.]+)$ pattern states that from begin to end there can not be any ? or . or / characters.