gallery & albums ok, but 404 on image pages :: .htaccess?

Hi there.

I have have used zenphoto for a photographic gallery since 2007. Love it! Especially the slick integration from Lightroom!

The only thing is that for some reason (probably after an update a few months back that I didn't test, i think) whenever one clicks from the album page to an image there a 404 that is being caught by my wordpress site. Wordpress is in the root and zenphoto is under it in /photography

any suggestions as to what the deal may be? I've looked extensively though the user guide, trouble shooting, searched this forum, permissions ok, not using php safe mode, upgraded zenphoto 1.4.4, reinstalled zenphoto, created a fresh zenphoto install.... but no luck yet.

I also copied the database tables into a new database and did a fresh install in a subdomain and it was fine. Must just be a conflict because as it is under wordpress (which it has been for years now).

The wordpress /.htaccess file looks like this:

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

# END WordPress

# no directory listing
IndexIgnore *
Options -Indexes

and the zenphoto /photography/.htaccess is standard with the setup (with RewriteBase /photography of course).

FYI, I am using the default theme (had a beautiful custom theme that matched my site, but it broke with an upgrade a year ago and haven't had a chance to fix it yet, been traveling round the world for 5 years in places with crappy internet...)

See the problem here:
http://www.exploringbliss.com/photography/

Any suggestions would be greatly appreciated.

Many thanks!

Comments

  • See: http://stackoverflow.com/questions/5061880/this-is-the-htaccess-code-in-wordpress-i-dont-understand-how-it-works-can-so

    I am not sure why this does not also cause issues with album links, though. You should try removing the Wordpress `.htaccess` and see if things work. If so, then you know that the above it the issue.

    If that is the case you need to add a `RewriteCond` to exclude links with "photography" as the folder name. Sorry, I am not well enough versed in rewrite rules to tell you how to do this.
  • acrylian Administrator, Developer
    You could try something like this:
    `RewriteRule ^photography/(.*)?/$ photography/$1 [L,R=301]`
    Not sure where to place it but probably try first right after the rewrite base.
  • hi guys, thanks for the input.

    Getting closer now:

    * when I delete the wordpress installation so that there is nothing in the root folder except /photography , I get the error below. And when I put wordpress back, the .htaccess catches it and redirects to the wordpress 404 page.

    ----------------------
    Forbidden

    You don't have permission to access /photography/new_zealand/20081223-NewZealand-9779.jpg.php on this server.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
    ----------------------

    * Now here is the interesting bit: I moved my test zenphoto installation that was working fine in a subdomain from the root to /test and the SAME ERROR OCCURED! Then to double-check, I installed a completely fresh installation in a test subdomain in a subdirectory ( /test ) and i get the SAME error.

    In other words, the current version of zenphoto doesn't seem to work out-of-the-box in a subdirectory! The setup works fine in root though.

    Thanks for the support,
    Fraser
  • acrylian Administrator, Developer
    Zenphoto works fine both in the root of domains or subdomains and also subfolders actually.

    If you move Zenphoto from and to folders and use modrewrite you always need to either run setup or change the rewritebase of the htaccess file. Otherwise it of course will not work.

    On a domain/subdomain root that would be /. On a folder /<folder>.
  • Somewhere on this forum there was a discussion of a user having problems with some security module that did not like the extension `.jpg.php`. (Sorry, I cannot find the post at the moment.) So maybe changing the `mod_rewrite suffix` to maybe "\view" will fix the issue.
  • Thanks again for the suggestions.

    Here is what I have found doing completely fresh installs and uploading 1 image in an album called "album".

    1) On my host (rochen.com) zenphoto 1.4.4 works fine in the root using mod rewrite. ex: http://test2.exploringbliss.com/album/_MG_0930-1024.jpg.php

    2) However, on my host (rochen.com) zenphoto 1.4.4 doesn't work with mod rewrite when the installation is contained in a subdirectory (it is fine without mod rewrite). ex: http://test.exploringbliss.com/test/album/_MG_0930-1024.jpg.php

    3) on a local MAMP install everything is fine, both root and subdirectory installs work.

    But I have no clue as to why this may be. It has been working fine on the host since 2007 until sometime recently. The only variable I know that has changed is a zenphoto upgrade. Perhaps my host has upgraded something at their end, but what and when I do not know.

    My host's PHP version is 5.3.20 and MySQL version is 5.1.66 (warnings in the install). The other warning I get is because PHP display_errors [is enabled].

    So do I have to downgrade zenphoto?

    Thanks guys for everything so far.
  • I seem to be having the same problem, that access to the albums is fine, but selecting on the thumbnail gives a message like:

    -- begin paste --

    You don't have permission to access /webphotos/201211a-McMichael/di_20121106_142734_mcmichael_billvazan_1989_shibagaushard.jpg.php on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    -- end paste --

    I don't recall having that problem before. I was running on v.1.4.3.2 , and just upgraded to v.1.4.4 with the same result. When I ran the setup, it didn't like the way htaccess was configured, so it updated that.

    Strangely enough, slides shows seem to work fine. Go to http://daviding.com/webphotos/201211a-McMichael , and "View Slideshow", and that works.

    It's just getting from the thumbnail to image that seems to be a problem.

    My versions read:

    PHP version: 5.2.17
    Graphics support: PHP GD library bundled (2.0.34 compatible)
    supporting: gif, jpg, jpeg, png, bmp
    PHP memory limit: 96M (Note: Your server might allocate less!)
    MySQL version: 5.1.65

    I seem to recall also having the PHP display_errors warning on setup.
  • You can set the `DEBUG_IMAGE_ERR` define to `true` in `global-definitions.php` to get any Zenphoto debugging information recorded in your debug log. If something is recorded then it may help discover what is causing this. If not, then the 403 error is not comming from Zenphoto.
  • I sent a note to my hosting provider support (Site5). This problem is not with Zenphoto, but with the environment. They responded:

    -- begin paste --
    We apologize for this situation. I checked Apache logs and I found that because of mod_security, that type of link .jpg.php was blocked by a mod_security rule.

    I went ahead and I fixed this and now you should be able to load your website without any issue or error.
    -- end paste --

    Problem solved. If you have this problem, ask your hosting provider support.
  • Debugging didn't return any error.

    Daviding, you hit the nail on the head! It's an issue with .jpg.php rewrite suffix. Funny that it works in root though...

    I have this open with my host....

    Maybe this would be a good thing to test in the setup checks?(although it doesn't help if your host sneaks in a mod_security rule change after you're up and running.)

    Thanks all for the comments and suggestions!
  • Core team,

    Food for thought:

    Would it make sense to set the default rewrite rule to .html instead of .php?

    I can imagine there are more than a few hosts out there that block .jpg.php extensions for security reasons, and this took a lot of hours to trace. Most new users would probably just give up and use something else. Actually, PHP sites are often hacked using this file extension to upload rogue php code to servers that think they are images. I've seen it happen a couple of times already on CMSes that run TinyMCE, for example.
  • acrylian Administrator, Developer
    That suffix is actually not a rewrite rule. It is an option you can set yourself. It is actually that way since the early days of Zenphoto. I neither don't remember that much reports about that nor did I ever encounter this issue on any of the hosts I used. Of course we don't get reports we cannot change things...

    Feel free to open a ticket about that maybe to discuss this further.
  • Probably the best would be not to set a default at all. We really do not know that these security rules would pass anything that looked like multiple suffixes.
  • acrylian Administrator, Developer
    But couldn't no default modrewrite suffix cause other issues like browser mistaking the link as an direct image?.

    Do we actually need the image suffix in the url additionally? Why not just <filename minus suffix>.<modrewrite suffix>? It's rewritten anyway.
  • Perhaps your code is more omniscient. Mine would have no idea what the suffix should be if it is not included. And of course, since the images are in the `albums` folder, not elsewehere how would mod_rewrite get confused?
  • acrylian Administrator, Developer
    I do admit I am not familiar how ZP uses the url internally but the original not rewritten one is:
    `index.php?album=albumname&image=filename.jpg`
    which is rewritten to
    `/albumname/filename.jpg.php`.

    So what would change if we leave one suffix out always like `/albumname/filename.php` and album links stay `/album/` since they are "directories"?

    If we use `/albumname/filename.jpg` some browser/server might have issues as this is not really an image itself.

    Besides I had never any issus with the two suffixes.
  • And just how would they have issues? Will they decide not to request the link if it is an image? Will they somehow bypass the server and directly get the image out of the either?

    I think not, I think that they all will make a request of the server which will process it via the rewrite rules as needed.

    And if they leave the suffix out, what file should Zenphoto look for?
  • acrylian Administrator, Developer
    Ok, as said not familiar with some url internals. I somehow mistook that the non rewritten links and their GET values are used internally and the rewritten ones are just "cosmetic" for display.

    So forget me thinking loud.
  • my host is pretty anal about security, but they've left .jpg.php open on my domain.

    But anyways, for the sake of security (and potentially saving hours problem solving), I have changed my suffix to .html in the config and used this .htaccess rule to forward old .php URLs to the new location:

    `RewriteRule ^(.*)\.jpg.php $1.jpg.html [R=301,L]`

    btw, if mod_security is blocking .jpg.php, those requests will be blocked before the above .htaccess rule is called.
  • Just confirming the same fix for this mod_security issue and, for the sake of Google, here's the error message I was getting:
    You don't have permission to access [.../imageName.jpg.php] on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    It's a server issue, not a ZenPhoto issue - it's the "imageName.jpg.php" bit that (on some servers) mod_security doesn't trust - but it can generally be sorted just by going to Admin > Options > General > URL options > mod_rewrite suffix:
    and changing from .php to .html
  • acrylian Administrator, Developer
    Yes, we even had a ticket on that (can't find it at the moment).
Sign In or Register to comment.