Forum Moderators: phranque
Been battling with this tricky rewrite script for 2 days now, getting on my nerves, thought I'd throw it out there and see if there's any suggestions or advice.
OK, I want any URL that matches a REAL file/directory to simply execute. For all other matches, I have a separate set of rules.
REAL files/directories:
http://www.example.com/users/
http://www.example.com/users/login.php
http://www.example.com/advertising/
http://www.example.com/faq/
http://www.example.com/item.php
http://www.example.com/items.php
For these I use a rewrite like this which should just continue the script normally and end the .htaccess file:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d
RewriteRule ^(.*) - [L]
This script just want to pass ANYTHING as true, so everything fails here and I'm not sure what else to try, then further down ...
VIRTUAL files/directories:
http://www.example.com/intel/
http://www.example.com/intel/item.php
http://www.example.com/gigabyte/
http://www.example.com/gigabyte/item.php
http://www.example.com/asus/
http://www.example.com/msi/
For this I use this script, which is WORKING (except that it is also working on any of the REAL files):
RewriteRule ^(.*)/$ /items.php [L]
RewriteRule ^(.*)/item.php$ /item.php [L]
Problem: I need the script to terminate normally if it finds a REAL existing file/directory!
Regards
Not sure where that "DOCUMENT_ROOT" #*$! came from, some dude that was trying to "help" actually set me back!
Here's the new WORKING (I hope) script:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*) - [L]
RewriteRule ^(.*)/$ /items.php [L]
RewriteRule ^(.*)/item.php$ /item.php [L]
Can anyone see any possible issues?
Regards
Start and end anchors are not required on a ".*" pattern standing alone.
When "^" or "$" is found adjacent to ".*", then both may be eliminated, as they add no meaning.
So, your code could be shortened/simplified to:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
#
RewriteRule /$ /items.php [L]
RewriteRule /item.php$ /item.php [L]
Jim