1

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?

1
  • 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, 2012 at 14:44

2 Answers 2

2

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.

2
  • 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, 2012 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.
    – MrWhite
    Apr 21, 2014 at 22:20
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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