Forum Moderators: phranque
Please can someone help with the following:
I have 2 seperate RewriteRules for the frist condition
the below works but seems to effect all the other rules
anyone any idea's, have I maybe ovver complecated these rules?
Options +FollowSymLinks
RewriteEngine on
#Removes trailing slash from URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ [%{HTTP_HOST}...] [R=301,L]
RewriteRule ^([^.]+)$ /dynamic.php?feature=$1 [L]
(this only works if I comment the line below idealy need 1 rule to allow either $1 or $1/$2)
#RewriteRule ^([^.]+)/([^.]+)$ /dynamic.php?feature=$1§ion=$2 [L]
I have tried to get the rules below to work by focing the trailing slash but this will not work with the above
# Force trailing slash on directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+[^/])$ $1/ [R,L]
RewriteRule ^dining/([^.]+)-([^.]+)\.php$ dining.php?county=$1&town=$2 [R,L]
RewriteRule ^([^.]+)/dining dining.php?town=$1 [L]
RewriteRule ^([^.]+)/eatingout/([^.]+) eatingout.php?town=$1&accountname=$2 [L]
Put your rules in order, external redirects first, from most-specific to least-specific, then internal rewrites, again from most-specific to least-specific.
By checking for !-f, your "force a slash" rule adds a slash to any file that does not exist. Instead, I think you want to add a slash to any directory that would exist if the URL had a slash on it.
# Redirect to remove trailing slash from URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
#
# Redirect to add trailing slash on directories
RewriteCond %{REQUEST_FILENAME}/ -d
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
#
# More-specific rewrites first
RewriteRule ^dining/([^/\-]+)-([^/.]+)\.php$ /dining.php?county=$1&town=$2 [R,L]
RewriteRule ^([^/]+)/dining$ /dining\.php?town=$1 [L]
RewriteRule ^([^/]+)/eatingout/([^/.]+)$ /eatingout.php?town=$1&accountname=$2 [L]
#
# Then least-specific "catch-alls"
RewriteRule ^([^/]+)/([^/.]+)$ /dynamic.php?feature=$1§ion=$2 [L]
RewriteRule ^([^/.]+)$ /dynamic.php?feature=$1 [L]
Jim