Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
    
Why "Of course, this does not work"? I see nothing wrong here (unless there is mistake in folder name (missing/extra symbol or wrong case). –  LazyOne Mar 27 '12 at 14:44
add comment

2 Answers

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.

share|improve this answer
1  
Your first example is a bit wrong (I'm refering to the second ^ character -- must be just typo). Something like this will be enough (could add NC flag as well if case-insensitivity is required) RewriteRule ^wordpress/ - [L] –  LazyOne Mar 27 '12 at 14:42
    
The first example is still wrong, the .$ matches just a single character before the end of the URL (after wordpress/) so probably won't match anything. Best to omit this entirely, as in LazyOne's comment. –  w3d 2 days ago
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.