views:

4095

answers:

11

I'm trying to have the modrewrite rules skip the directory vip. I've tried a number of 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 entirely ignore the /vip/ directory so that all requests pass directly to the folder?

A: 

I'm not sure if I understand your objective, but the following might do what you're after?

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

This will cause a URL such as http://www.example.com/vip/fred.html to be rewritten without the /vip.

Peter Howe
+1  A: 

Thanks, Peter. That hasn't done it, unfortunately.

As points of clarity:

  • It's hosted on Dreamhost
  • The folders are within a wordpress directory
  • the /vip/ folder contains a webdav .htaccess etc (though I dont think this is important
Same problem here
matdumsa
+6  A: 

Try putting this before any other rules.

RewriteRule ^vip - [L,NC]

It will match any URI beginning vip.

  • The - means do nothing.
  • The L means this should be last rule; ignore everything following.
  • The NC means no-case (so "VIP" is also matched).

Note that it matches anything beginning vip. The expression ^vip$ would match vip but not vip/ or vip/index.html. The $ may have been your downfall. If you really want to do it right, you might want to go with ^vip(/|$) so you don't match vip-page.html

Patrick McElhaney
BTW, I had the same problem a few weeks ago, and this worked for me on Apache/2.2.8 (UNIX).
Patrick McElhaney
+1  A: 

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

RewriteEngine off

In that .htaccess to stop use of mod_rewrite (not sure if you're using mod_rewrite in that folder, if you are then that won't help since you can't turn it off).

Jay
Wouldn't help, as the .htaccess in the parent directory, which does have Rewrite rules, would get evaluated long before Apache looked into /vip.
Marc B
A: 

Thanks everyone for your great answers!

Unfortunately it turns out it wasn't a great question...! It lacked clarity. What I was TRYING to ask was not how do I rewrite the URL to exclude the /vip/, but rather this:

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

Thanks again for all your work!

I've edited the post to include your rephrased question.
Patrick McElhaney
+3  A: 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

This says if it's an existing file or a directory don't touch it. You should be able to access site.com/vip and no rewrite rule should take place.

A: 

I'm trying to achieve the same thing... need mod_rewrite to COMPLETELY ignore a specific directory under the parent directory... haven't had any luck... even when i put a new .htaccess file in the directory that i want to be ignored with "RewriteEngine off", still doesn't work.

anyone? Bueller?

Jono
Try`<Directory /hide-this>Order Deny, AllowDeny from All</Directory>`in your .htaccess.
CodeJoust
A: 

I’ve had the same issue using wordpress and found that the issue is linked with not having proper handler for 401 and 403 errors..

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

These conditions are already supposed not to rewrite the url of existing folders but they don’t 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 the /misc/myerror.html,

matdumsa
A: 

This is a really annoying stupid bug, I have been searching the web for ages finally come accross tis post and still nothing works :s

Might be worth also pointing this here... http://www.addedbytes.com/blog/ignore-directories-in-mod-rewrite/

adam
A: 

Thank you so much Patrick. I have been trying to figure this out for ages and this was the one thing that worked.

Designer023
A: 

In summary, the final solution is:

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 posted more about the cause of this problem in my specific situation, involving Wordpress and WebDAV on Dreamhost, which I expect many others to be having on my site.

Cody A. Ray