Ignore a folder using htaccess?

Hi,

I’m using the ReWriteEngine to create pretty URLs with WP…


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

and it works great. ?page_id=29 turns into /career-opportunities etc.

In my root I have the usual wp-content, wp-includes, wp-admin folders, but I also have my ‘zenphoto’ which is a piece of gallery software.
And everytime I use the .htaccess file above, in my root, it messes up my zenphoto gallery :frowning: It spits out raw html.
I already have an .htaccess file in my ‘zenphoto’ folder, so it’s possibly confusing things with the two.

How do I set my Rewrite above to ignore my ‘zenphoto’ folder when it does its rewrite thing?

<Directory /var/www/zenphoto>
    RewriteEngine off
</Directory>

You can do that. You could also use RewriteCond.

Thanks for the reply, sorry for being late.

Now I have:


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond &#37;{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<Directory htdocs/zenphoto>
    RewriteEngine off
</Directory>

# END WordPress

But I now get a 500 Internal Server Error.

How do I know what this should be: htdocs/zenphoto ??

You can try the absolute path. You could also do <Location /zenphoto> instead.

i2,

The WP mod_rewrite is designed to “take over” a website in the belief that everything belongs to it. However, you also need to know when NOT to include some statements (you’re overworking mod_rewrite to NO useful purpose).


# BEGIN WordPress
[COLOR="Red"]<IfModule mod_rewrite.c>
# You obviously have it enabled so remove this @#$%![/COLOR]
RewriteEngine On
[COLOR="Red"]RewriteBase /
# NOT required here - and is meant to undo mod_alias redirects[/COLOR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
[COLOR="Blue"]RewriteCond %{REQUEST_URI} !^/?zenphoto/[/COLOR]
RewriteRule . [COLOR="Red"]/[/COLOR]index.php [L]
[COLOR="Red"]# You are already in DocumentRoot!
# Specifying / here could force Apache into a 'nix mode where
# it could redirect to the physical path[/COLOR]
[COLOR="Red"]</IfModule>
# Ditto the above[/COLOR]
# END WordPress

The blue line is what you’re asking for.

Regards,

DK

Thanks for the reply.

OK, I used this:


# BEGIN WordPress
RewriteEngine On
RewriteCond &#37;{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?zenphoto/
RewriteRule . /index.php [L]
# END WordPress

but still had no success :frowning:

Is there something special I need to do to my PermaLinks options in WordPress.

It displays my pretty names fine in WP, but can’t display my gallery :frowning:

Can you possibly replicate it at your end if it’s not too much trouble and let me know if you have any success?

Many thanks for your help so far.

Is the zenphoto directory/name at the web root? I.e.; domain.com/zenphoto? If not, this is why it’s failing. because it wants to see it at the start of the string ^/ rather than just anywhere in the URI string. Does this make any difference by changing it to (as a test to see if it ignores it, you probably won’t want to keep it this way, and can change it to be specific later, after you confirm if it makes any difference):

RewriteCond %{REQUEST_URI} !zenphoto [NC]

Hi folks,

When I login to my FTP I have three folders
htdocs
logs
_private

Within htdocs, I have
wp-content
wp-admin
wp-includes
zenphoto

Within the same htdocs, I have my ‘.htaccess’ file:


# BEGIN WordPress
RewriteEngine On
RewriteCond &#37;{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?zenphoto/ *
RewriteRule . /index.php [L]
# END WordPress

So yes, it is domain.com/zenphoto.

Tried replacing the * line with your RewriteCond %{REQUEST_URI} !zenphoto [NC] one Tim, but still no joy.

Exact same error, just spitting out bits of raw html to the web page on my zenphoto gallery, cutting into the code half-way through, only displays from about the middle down to the footer.

You used

RewriteCond %{REQUEST_URI} !^/?zenphoto/ *

?

Did you mean to have a / and a space and then *? Just remove the final white space and * and see if that helps.
I didn’t realize you were getting an error (I missed that part). Does it error when you allow access to zenphoto? Also, remove the trailing forward slash on zenphoto/ in case it’s being accessed without being fully resolved to the URL (it should automatically, but just in case, and it doesn’t appear it’ll conflict with any similarly named file or directory that would star with the same name anyway, so it would be safe)

i2,

Sorry, I’d missed that you’d used {REQUEST_FILENAME} instead of {REQUEST_URI}. Change them both and let us know if that doesn’t resolve the problem for you.

Yes, the trailing * is an error.

Regards,

DK

I was wondering if they actually used the trailing * in their actual rewrite conditional check, or if it was a typo. I assumed they didn’t actually use it, but made a point to point it out anyway, just in case.

So, just to confirm, I’ve tried both


# BEGIN WordPress
RewriteEngine On
RewriteCond &#37;{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^/?zenphoto
RewriteRule . /index.php [L]
# END WordPress

and:


# BEGIN WordPress
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/?zenphoto
RewriteRule . /index.php [L]
# END WordPress

still no luck.

I tried both, and now when I access ‘zenphoto’, I get a File Open prompt, to open/save the PHP file.

Not sure if it’s useful, but here’s my .htaccess code for zenphoto:


# htaccess file version 1.1.4.0
# Update the above and the define in setup.php when you make changes to the rewrite rules!
# NOTE: Change the RewriteBase below to the absolute path to your zenphoto directory. (Or let setup.php do it for you!)

<IfModule mod_rewrite.c>
  RewriteEngine On
  
  #### !!! Change this to the web path (eg: http://www.yourwebsite.com/photos --> /photos) !!!
  RewriteBase /zenphoto
  ####
  
  RewriteRule	^admin/?$                       zp-core/admin.php [R,L]

  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^.*$ - [R,L]
  
  RewriteRule index\\.php$                     index.php [L,QSA]
  RewriteRule ^page/([0-9]+)/?$               index.php?page=$1 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/?$      index.php?p=$1 [L,QSA]
  RewriteRule ^(.*)/page/([0-9]+)/?$          index.php?album=$1&page=$2 [L,QSA]
  
  #### Rewrite rule addtion for search
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/fields([0-9]+)/(.*)/([0-9]+)/?$      index.php?p=$1&searchfields=$2&words=$3&page=$4 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/fields([0-9]+)/(.*)/?$      index.php?p=$1&searchfields=$2&words=$3 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/archive/(.*)/([0-9]+)/?$      index.php?p=$1&date=$2&page=$3 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/archive/(.*)/?$      index.php?p=$1&date=$2 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/tags/(.*)/([0-9]+)/?$  index.php?p=$1&searchfields=4&words=$2&page=$3 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/tags/(.*)/?$ 					 index.php?p=$1&searchfields=4&words=$2 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/(.*)/([0-9]+)/?$      index.php?p=$1&words=$2&page=$3 [L,QSA]
  RewriteRule ^page/([A-Za-z0-9\\-_]+)/(.*)/?$      index.php?p=$1&words=$2 [L,QSA]
   
  RewriteRule ^(.*)/image/(thumb|[0-9]{1,4})/([^/\\\\]+)$    zp-core/i.php?a=$1&i=$3&s=$2 [L,QSA]
  RewriteRule ^(.*)/image/([^/\\\\]+)$          zp-core/i.php?a=$1&i=$2 [L,QSA]
  ####
   
  # Catch-all - everything else gets handled in PHP for compatibility.
  RewriteRule ^(.*)/?$                        index.php?album=$1 [L,QSA]
</IfModule>

Would it make sense to combine the two .htaccess files, keep it in the root, and delete my zenphoto .htaccess file?

Really appreciate your patience guys.

Let me ask you this; When you experience the problems with the site, see errors, etc., in what way are you accessing it? You want it to ignore the zenphoto directory, but where/how and in what capacity? It sounds like the rules you have are interfering with that directory that you wanted ignored, because you actually do want to still access it in some capacity, in which case you would indeed need to consider the other area and (possibly) its own rewrite rules.

Really, you should be able to leave the rewrite rules alone in the zenphoto directory and simply figure out how you want the other rules to ignore or use it. Right now the .htaccess file in the parent directory that zenphoto is housed within, will affect and override the rules you have in the zenphoto sub directory. it should be a simple fix, I just don’t fully understand what you need to accomplish. For now, it seems that the
RewriteCond %{REQUEST_URI} !^/?zenphoto line is probably ignoring that rewrite rule, but when you access the sub directory of zenphoto, that conditional no longer sees it as ^/zenphoto, but as . or /, regarding the rewrite conditional.

Thanks for the reply Tim.

I am accessing it by www.test.com/zenphoto through my browser.
I want to ignore it when its rewriting my WP files in the parent directory.

Really stuck on this one. Any advice you can give would be brilliant.

I basically want my main .htaccess file to affect all folders except zenphoto, and for zenphoto to be affected by the .htaccess file in its own directory.

I think I might stick my wordpress installation under another directory and save myself a lot of hassle.

i2,

That’s exactly what you get with the zenphoto exclusion in DocumentRoot’s .htaccess (in order to be able to access the zenphoto directory where its .htaccess will kick in).

Regards,

DK