I'm trying to track down an issue with a set of rewrite rules that I'm using to convert links from www.mysite.com/dir/page (and /dir/page/) format into a query-string for a script. To give a better example:
www.example.com/projects/foo => /index.php?projects/foo
www.example.com/projects/foo/ => /index.php?projects/foo/
However, any file that exists in htdocs overrides the script. So if I had a file called 'photo.jpg' in htdocs/projects/foo and someone requested www.example.com/projects/foo/photo.jpg, Apache would handle it as a file instead of redirecting to the script. This saves me writing more code to handle images, and probably a bit of CPU time as well.
Now, this works great, as long as the URL ends with a forward slash. If this is not the case, then my script sends out a Location: header to redirect it, like Apache does with directories -- if you request the directory /foo, you get a 301 Redirect to /foo/ (which then grabs the index page).
If the URL doesn't end with a forward slash, the URL goes from www.example.com/foo/bar to www.example.com/foo/bar/. This works fine if the directory /htdocs/foo/bar/ doesn't exist. If that directory *does*
exist, then the user gets sent to www.example.com/foo/bar/?foo/bar/ instead of www.example.com/foo/bar/.
These are my rewrite rules, as stored in the .htaccess file:
- Code: Select all
RewriteEngine On
RewriteBase /
# Apply to primary hosts only
RewriteCond %{HTTP_HOST} ^philpem.me.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.philpem.me.uk$ [NC]
# This makes sure AWStats can get through
RewriteCond %{REQUEST_URI} !^/awstats.* [NC]
# Additional rules -- temp dir
RewriteCond %{REQUEST_URI} !^/temp.* [NC]
# Enable the next condition if you want physical files to override the CMS
# (this should normally be on, otherwise images, etc. will be forwarded to the
# CMS, which is generally not what you'd want to happen)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(.*)$ index.php?$1 [L]
Can anyone see what I'm doing wrong here?
Thanks,
Phil.