I have a few rewrite rules like these

RewriteRule ^dir/(.*)-something.html otherdir/file1.php?var1=val&var2=$1 [L,NC]
RewriteRule ^dir/ otherdir/file2.php?var1=val [L,NC]

dir/ is not a real directory. Everything above works as expected.

However, the user is able to type anything like

mysite.com/dir/asdfasdfasdfsdf

And they are still redirected to file2.php. If the user types in just garbage I'd like to serve a 404 instead.

I'm guessing I need a RewiteCond that will test for blank space after the slash and only then serve file2.php, but I'm unsure how to write it.

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

I think if you put a $ at the end of dir/ it will do the trick (note that I haven't tested this, so please try it out before voting me up or anything). The $ means "end of string" in the same way that ^ means "beginning of string".

RewriteRule ^dir/$ otherdir/file2.php?var1=val [L,NC]

Good luck!

--jed

link|improve this answer
Worked like a charm! Thanks! I can't vote up yet (reputation) or I would. – Stephen Apr 1 '10 at 0:04
Also made me realize that I needed a $ after the .html in the other rules. Appreciate it! – Stephen Apr 1 '10 at 0:11
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.