Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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