Need Help with RewriteCond %{REQUEST_FILENAME}

Topics: User Forum
Nov 8, 2008 at 4:18 PM
I've been struggeling with this for a few days now and I'm not that savy with RegEx so this is driving me insance.

I am trying to rewirte the following url:




Where the file name in the first url is a non-existing file (CdxaVWqZ7k-81Db_ofM1Vw.aspx)

Here is what I have for my rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*?)?/app/sites/(.*)\.aspx(\?[-A-Z0-9+&@#/%=~_|!:,;].*)? $1/app/sites/index.aspx?webSiteID=$2 [L]

My test file contains:

While this works fine under II5 on Windows XP, it does not on Windows 2003. Under Windows 2003 the first test url gets rewritten twice:
1. To http://win2003/application/app/sites/index.aspx?webSiteID=CdxaVWqZ7k-81Db_ofM1Vw
2. To http://win2003/application/app/sites/index.aspx?webSiteID=index

I am trying to add something like:
RewriteCond %{REQUEST_FILENAME} !index.aspx
to the rules but that doesn't seem to be working.

What am I doing wrong. I'm sorry if this is newbie mistake.

Nov 11, 2008 at 12:57 AM
You mentioned you have a "test file"
Are you using the testdriver? 
The problem with the testdriver is it will not work with server variables, as you have in your RewriteCond.

The syntax with a leading ! to negate a pattern is not supported.
Lots of people think it is. It's a common misconception.
I posted that information probably 3 times in the last month on this forum.

If it were me I would write your rule differently.  Like so:

RewriteRule (.*?)?/app/sites/(?!index)(.*)\.aspx(\?[-A-Z0-9+&@#/%=~_|!:,;].*)? $1/app/sites/index.aspx?webSiteID=$2    [L]

This one just excludes index.aspx from matching.  the (?!index) does that trick.

So, this url will match, and be rewritten:

This one will not

Nov 13, 2008 at 10:26 PM
Thanks, I ended up with the same solution. My issue was that I couldn't figure out how to exclude the index page (?!index) but I found the solution on Google. Thanks for the reply and keep up the great work!