Mobile app version of vmapp.org
Login or Join
Welton855

: 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,

@Welton855

Posted in: #Htaccess #ModRewrite

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

2 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

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 (/|$).

10% popularity Vote Up Vote Down


 

@Gonzalez347

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme