Having mod_rewrite not rewrite requests for a particular directory
.htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, mod-rewrite, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :I have many forward rules written in my .htaccess file. However, for the requests to a certain directory and its subdirectory, say wordpress, I don't want to use the forward rules.
RewriteEngine On
RewriteCond %REQUEST_URI wordpress
RewriteRule ^.*$ - [NC,L]
RewriteRule ...
RewriteRule ...
RewriteRule ...
RewriteRule ...
Of course, this does not work. How should I modify the second line?
This should work for a single directory (for example your wordpress directory)...
RewriteRule ^wordpress/.$ - [PT]
If you want mod_rewrite to ignore all directories, try something like this
RewriteCond %REQUEST_FILENAME -d [NC]
RewriteRule .* - [L]
The RewriteCond is true if the path is a directory, and the Rule will stop rewrite processing. Just be sure to put this at the beginning of your ruleset.
As LazyOne notes, your example should work, more or less. (That is, it might match some URLs you didn't intend to match, but it should indeed stop any URLs containing wordpress from being rewritten.) The way I'd recommend writing it is this:
RewriteEngine On
RewriteBase /
RewriteRule ^wordpress/ - [L]
# other rewrite rules here...
This will prevent any URL paths beginning with wordpress/ from being rewritten. If you also want to prevent rewriting for http://www.yoursite.com/wordpress without the trailing slash, you can either add a separate rule for it:
RewriteRule ^wordpress$ - [L]
or just replace the trailing / in the first rule above with (/|$).
Comments
Post a Comment