Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing URL access only after mod_rewrite

Status
Not open for further replies.

courtarro

Programmer
Oct 26, 2005
16
US
Hypothetical situation: I've got a PHP script:

/dostuff.php

It takes a parameter "thing":

/dostuff.php?thing=monster

But I'm using mod_rewrite to make it look better, so the URL I want users to see (and use) is:

/dostuff/monster

For this purpose I've created a simple rewrite rule:

RewriteRule ^dostuff/(.*)$ dostuff.php?thing=$1

However, I then would like to prevent users from accessing the original script with "dostuff.php" - I want that to hit a 404 (or 403). I tried doing this:

RewriteRule ^.*\.php nonexistentpage
RewriteRule ^dostuff/(.*)$ dostuff.php?thing=$1

But for some reason, this blocks all access to the script, even when using the "dostuff/" version. I don't understand why that occurs - does Apache loop through the RewriteRules multiple times? If the URL doesn't include ".php" until after the second rule, why would the first rule end up being applied?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top