How to ignore a directory in mod_rewrite?

I am trying to make modrewrite rules skip the vip directory. I tried several things, as you can see below, but to no avail.

 # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #RewriteRule ^vip$ - [PT] RewriteRule ^vip/.$ - [PT] #RewriteCond %{REQUEST_URI} !/vip RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 

How do I get modrewrite to completely ignore the /vip/ directory so that all requests go directly to the folder?

Update:

As points of clarity:

  • It is hosted on Dreamhost.
  • Folders are in the wordpress directory
  • the / vip / folder contains the webdav.htaccess file, etc. (although I do not think this is important
+68
apache mod-rewrite
02 Oct '08 at 16:23
source share
11 answers

Try to put this before any other rules.

 RewriteRule ^vip - [L,NC] 

It will match the start of the vip URI.

  • - means do nothing.
  • L means that this should be the last rule; ignore everything that follows.
  • NC means “no” (so “VIP” also matches).

Note that this corresponds to the start of vip . The expression ^vip$ will match vip , but not vip/ or vip/index.html . Maybe it was $ . If you really want to do it right, you can go with ^vip(/|$) so that you don't match vip-page.html

+118
Oct 02 '08 at 17:22
source share
 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

This means that it does not affect the existing file or directory. You must have access to site.com/vip, and there should be no rewriting rules.

+13
Nov 07 '08 at 21:32
source share

The code you add and all the answers that provide the rewriting rules / conditions are useless! The default WordPress code already does everything you need to:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] 

These lines say, "If this is NOT an existing file ( -f ) or directory ( -d ), pass it to WordPress. Adding additional rules, no matter how accurate or good they are, is redundant - you should already be covered by WordPress rules!

So why don't they work ???

.htaccess in the vip directory causes an error. The same thing happens if you password protect the directory.

Here is the solution:

 ErrorDocument 401 /err.txt ErrorDocument 403 /err.txt 

Insert these lines before the WordPress code, and then create /err.txt. Thus, when it comes to your WebDAV (or password protected directory) and crashes, it goes to that file and gets into the existing default WordPress condition ( RewriteCond %{REQUEST_FILENAME} !-f ).

+9
Aug 09 '13 at 23:27
source share

You mentioned that you already have a .htaccess file in the directory that you want to ignore - you can use

 RewriteEngine off 

In this .htaccess, stop using mod_rewrite (not sure if you are using mod_rewrite in this folder, if you do not help then, since you cannot disable it).

+8
02 Oct '08 at 18:31
source share

So the final decision:

 ErrorDocument 401 /misc/myerror.html ErrorDocument 403 /misc/myerror.html # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress 

I talked more about the cause of this problem in my particular situation, including Wordpress and WebDAV on Dreamhost, which, as I expect, many others will have on my site .

+8
Aug 08 '10 at 17:35
source share

Try replacing this part of your code:

  RewriteRule ^ vip /.$ - [PT] 

... with the following:

  RewriteCond% {REQUEST_URI}! (Vip) [NC] 

This should fix the situation.

+4
Jun 11 '13 at 6:55 on
source share

I had the same problem using wordpress, and it turned out that the problem was due to the lack of a proper error handler 401 and 403.

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

These conditions should no longer rewrite the URLs of existing folders, but they do not do their job for password protected folders. In my case, adding the following two lines to my root .htaccess fixed the problem:

 ErrorDocument 401 /misc/myerror.html ErrorDocument 403 /misc/myerror.html 

Of course you need to create / misc / myerror.html,

+3
Apr 19 '10 at 1:31 on
source share

It works...

 RewriteRule ^vip - [L,NC] 

But make sure this is the first rule after

Rewriteengine on

i.e.

 ErrorDocument 404 /page-not-found.html RewriteEngine on RewriteRule ^vip - [L,NC] AddType application/x-httpd-php .html .htm RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d etc 
+3
Feb 27 2018-11-22T00:
source share
 RewriteCond %{REQUEST_URI} !^pilot/ 

- a way to do it.

+3
Nov 29
source share

In my case, the answer of brentonstrine (and I see that matdumsa also had the same idea) was correct ... I would like to vote for their answers, but being new here, I have no "reputation", so I have to write the full answer to emphasize what I consider the real key.

Some of these answers have successfully stopped using WordPress index.php ... but in many cases the reason for this is that there is a real directory with real pages in it that you want to display directly, and

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

the lines already take care of this, so most of these decisions are a distraction in a case like mine.

The key was brentonstrine's to understand that the error was a secondary effect caused by password protection in a directory that I tried to display directly. Inserting

 ErrorDocument 401 /err.txt ErrorDocument 403 /err.txt 

and creating error pages (I actually created err401.html and err403.html and made more informative error messages). I stopped the 404 response that was generated when it could not find any page for 401 authentication, and then the folder worked as expected ... showing the Apache login dialog, then the contents of the folder or failure, my page with error 401.

+2
Oct 21 '14 at 23:02
source share

I'm not sure if I understand your goal, but the following can do what you need?

 RewriteRule ^/vip/(.*)$ /$1?%{QUERY_STRING} [L] 

This will cause the URL, for example http://www.example.com/vip/fred.html , to be rewritten without / vip.

-one
Oct 02 '08 at 16:49
source share



All Articles