: Having mod_rewrite not rewrite requests for a particular directory I have many forward rules written in my .htaccess file. However, for the requests to a certain directory and its subdirectory,
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?
More posts by @Welton855
2 Comments
Sorted by latest first Latest Oldest Best
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 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 (/|$).
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.