tags:

views:

276

answers:

2

For my site I have a RewriteRule that points the URL http://www.mysite.com/work to a work.php file. I also have a directory called "work" that has files in it, like project1.php, project2.php, etc...

What rules would I have to write so that the URL http://www.mysite.com/work knows to go to the work.php file, but the URL http://www.mysite.com/work/project1 knows I mean to go inside the directory "work" and display the project1.php file?

EDIT: Should point out, this is what I'm currently working with:

RewriteEngine On
RewriteBase /beta/
RewriteRule ^([a-z]+)$ $1.php [L]

Any additional tips to improve this security-wise? (Stopping directory jumping, etc...)

+3  A: 

Try this:

RewriteEngin On
RewriteBase /
RewriteRule ^work$ /work.php [QSA,L]

That will ensure that http://www.mysite.com/work (no trailing slash) will go to your work.php file.

If you also want http://www.mysite.com/work/ (with trailing slash) to go work.php, add this line just above the last RewriteRule.

RewriteRule ^work/$ /work [R=301,QSA,L]

That will redirect it to the URL with no trailing slash thus, displaying the work.php file.

UPDATE: Since you already have a RewriteBase directive, just put the RewriteRule line(s) right after your RewriteBase but before your RewriteRule as the rule you're using a catch-all and will match everything.

sirlancelot
You answered before I included my current .htaccess file, doesn't seem to work if I just add your stuff in. Probably something to do with what I currently have?
Brandon
@Brandon, I updated my answer to match your revision.
sirlancelot
A: 

Try this rule:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php [L]
Gumbo
What’s the problem?
Gumbo
I'm not the one who down-voted it, but I'd guess the reason is your rule is too aggressive and will match any file that exists and not just `/work`, which is what OP wanted.
sirlancelot