LilMoke
LilMoke

Reputation: 3454

Rewrite URL, regex help

I am using the following Rewrite URL:

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

which works great for my use, but I need to restrict it to only act on text that does not contain a filename... for example, if I use the url www.somedomain.com/SomeName it works fine, but it also fires if I use www.somedomain.com/TestPage.aspx

So I am not sure if I need an additional Rewtire rule, or if the current one can be modified to disallow any text with an extension, for example.

Any help with this regular expression would be greatly appreciated.

Upvotes: 0

Views: 65

Answers (1)

Ass3mbler
Ass3mbler

Reputation: 3915

try adding this before the rewrite rule:

RewriteCond %{REQUEST_FILENAME} !-f

this condition check if the file requested exists and returns true if it doesn't (as it's negated with a !).

if you need not to fire the rule also for the directories, then add also this line:

RewriteCond %{REQUEST_FILENAME} !-d

Upvotes: 1

Related Questions