Forum Moderators: phranque
I need to create a htaccess rewrite rule and point the two URLs separately to different files.
whateverdomain.com/dir/foo_bar/
whateverdomain.com/dir/foo/
In the first instance I need to say the pattern with the underscore would rewrite the variables to var1.php and in the second case the URL without the _ would rewrite variables to var2.php. dir is a directory that would never have any underscores.
foo_bar and foo can contain numbers. Any ideas on how to do this?
Thanks
What happens though is, this URL whateverdomain.com/dir/foo_bar/ with the underscore resolves to the second rule instead of the first.
How do I force it to use the first rule so that foo_bar would be var1=foo and var2=bar ?
RewriteRule ^dir/([^/\.]+)/([^/\.]+)_([^/\.]+)/?$ /var1.php?dir=dir&var1=$1&var2=$2 [NC] [L]
RewriteRule ^dir/([^/\.]+)/?$ /var2.php?dir=dir&var1=$1 [NC] [L]
RewriteRule ^dir/([^/\.]+)_([^/\.]+)/?$ /var1.php?dir=dir&var1=$1&var2=$2 [NC,L]
#
RewriteRule ^dir/([^/_\.]+)/?$ /var2.php?dir=dir&var1=$1 [NC,L]
RewriteCond %{REQUEST_URI} !^/dir/
RewriteRule ^dir/(.*)$ http://www.example.com/dir/$1 [NC,R=301,L]
Unfortunately, there is no good way to detect casing errors on the path appended to "/dir/" using mod_rewrite -- And this is one reason why you should be very careful not to allow mis-cased URLs to resolve in the first place... Either redirect them, or let them go 404-Not Found.
Jim