19

I have been here: How to exclude a specific file in htaccess

and here: exclude files from rewrite rule in .htaccess

but neither worked. What might I be doing wrong?

.htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-content(/.*|)$ - [L] # don't take any action
RewriteRule ^wp-admin(/.*|)$ - [L] # don't take any action
RewriteRule ^wp-includes(/.*|)$ - [L] # don't take any action
RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$

RewriteRule ^moreinfo/(.*)$ http://www.kgstiles.com/moreinfo$1 [R=301]
RewriteRule ^healthsolutions/(.*)$ http://www.kgstiles.com/healthsolutions$1 [R=301]
RewriteRule ^(.*)\.html$ $1/ [R=301]
RewriteRule ^(.*)\.htm$ $1/ [R=301]
</IfModule>
Community
  • 1
  • 1
Christian
  • 735
  • 3
  • 10
  • 29

1 Answers1

43

To exclude a file, try something like this:

RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$ 

The rule will be skipped if the file is pureplantessentials.html.

Felipe Alameda A
  • 11,791
  • 3
  • 29
  • 37
  • it is still rewriting. Is there a specific place it should be? I put it at the end of my exclusions... – Christian Dec 23 '12 at 02:22
  • That's why an example is important. Please update your answer with an example to see how the incoming URL with the file to exclude looks. – Felipe Alameda A Dec 23 '12 at 02:25
  • Should I post my updated .htaccess file and show you how it looks? – Christian Dec 23 '12 at 02:35
  • I just posted my htaccess file in my question. www.kgstiles.com/pureplantessentials.html still redirects to www.kgstiles.com/pureplantessentials/ – Christian Dec 23 '12 at 02:37
  • Of course. You are excluding that file from applying the rules, that's why the requested URL remains the same. If you try with another file name the rules should be applied but they aren't either, because the conditions in the rule itself are not met, so the last rule (Repeated) applies and nothing is modified. – Felipe Alameda A Dec 23 '12 at 02:50
  • 1
    I'm not sure if it was a mistake by you or if something I did was contrary to what I said above, but by changing RewriteCond %{REQUEST_URI} !^/pureplantessentials\.html$ to RewriteCond %{REQUEST_URI} !^pureplantessentials\.html$ (without the first /), I was able to make this work. – Christian Jan 16 '13 at 04:58
  • Both had the same idea. The difference is the position of the directory inside the URI. I assumed it was the first subdirectory, but it isn't. Glad you found out the way to make it work. – Felipe Alameda A Jan 16 '13 at 05:48
  • What if it's a PHP file that's already being redirected to based on a previous rewrite rule? – NobleUplift Oct 18 '19 at 04:42