Hi,
I have a ton of rewrite rules in my .htaccess file, and I’m hoping to trim them down a bit. For example:
RewriteCond %{QUERY_STRING} nh=(\d+)
RewriteRule ^blog/cat_.+_c([0-9]+)\.html /cgi-bin/blog.cgi?cat=$1;nh=%1 [L]
RewriteRule ^blog/cat_.+_c([0-9]+)\.html /cgi-bin/blog.cgi?cat=$1 [L]
RewriteRule ^blog/article_.+_a([0-9]+)\.html /cgi-bin/blog.cgi?article=$1 [L]
RewriteRule ^blog/$ /cgi-bin/blog.cgi [L]
What I want to do, is stop anything processing IF the requested URI is either a directory, or a file that exists. So I could do:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} nh=(\d+)
RewriteRule ^blog/cat_.+_c([0-9]+)\.html /cgi-bin/blog.cgi?cat=$1;nh=%1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/cat_.+_c([0-9]+)\.html /cgi-bin/blog.cgi?cat=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/article_.+_a([0-9]+)\.html /cgi-bin/blog.cgi?article=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/$ /cgi-bin/blog.cgi [L]
But, as you can see, there is a LOT of repetition! (which will make managing it a PITA)
My question - is there a way I can put this up near the top of the .htaccess file, so that it will just ignore any rules above if it matches?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
TIA
Andy