1) I want to _not_ rewrite URIs that refer to actual files or directories, such as "/css/main.css".
1a) With the exception that I want directory URIs to end with a slash.
2) I want to remove the (optional) trailing slash from all other URIs.
3) Finally, I want to decompose URIs into query parameters, to be passed to my controller script, index.php. Different URIs will be decomposed in different ways.
Pretty standard stuff, yeah? Here's my .htaccess file:
- Code: Select all
Options None +FollowSymLinks
DirectoryIndex index.php
RewriteEngine On
# these preconditions satisfy my first objective
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# and 1a is handled automatically it seems (mod_dir?)
# here's number 2--and where things start to fall apart. this rule works on my
# development machine (Windows/Apache 2.2) but not on the production machine
# (Linux/Apache 1.3). by "doesn't work", i mean it triggers a 500 error
RewriteRule ^(.+)/$ $1 [R=301,L]
# so, on the production machine, i use this rule instead
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
# that takes care of the first two items; now for 3
# here i have to restate the preconditions from above--is there another way?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# for URIs of the form http://www.mywebstore.com/products/123, "123" maps to the
# query parameter "item-number". this rule works locally, but hoses the
# production server (500 error). same with the next rule
RewriteRule ^products/([0-9]+)$ index.php?controller=products&item-number=$1 [QSA,L]
# dum dee dum...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# for URIs of the form http://www.mywebstore.com/content/about, "about" maps to
# the query parameter "page"
RewriteRule ^content/([a-z]+)$ index.php?controller=content&page=$1 [QSA,L]
# and so on
# finally, i set up a catch-all for URIs that don't match any of the above
# patterns. this rule actually works in production (yay!)
RewriteRule ^(.*)$ index.php?controller=$1 [QSA,L]
The crux of the problem is I can't debug mod_rewrite on the production server. It's a shared host. I've gotten this far through trial and error. Any help would be greatly appreciated.