Url rewriting - removing parameter from image.php pages

Hi,

I don't know how to code a working rule to rewrite an url for the images pages of my gallery.

For some reason, I had to pass a parameter in the url of my images, so I have an url of this form :

/portfolio/album/subalbum/image.jpg?limit=12

I would like to rewrite this url without the parameter ?limit=12 :

/portfolio/album/subalbum/image.jpg

I've tried some urlrewriting rules in the .htaccess I've found at the root of my portfolio directory, but with no success...

If someone have an idea?

Comments

  • acrylian Administrator, Developer
    Most rewriting is done internally. Even if you rewrite the parameter it still must be there as otherwise the url does not match it. For example the image url of Zenphoto is `index.php?album=&image=` and becomes `//`

    you would have to add something like `/limit/12` to the url in rewritten form. But the question is what exactly is this parameter for? Can you do it differently maybe? Cookies, sessions etc?

    Btw. we strongely recommend to use the rewrite suffix so you have urls like `/portfolio/album/subalbum/image.jpg.html`. Otherwise searchengines seem to tend ot think this is an url to an image and not to a page with an image and rejects it.
  • Thank you Acrylian,

    This parameter is the way I used to limit the number of my images in my last images album (I've already posted something on the forum about a year ago about it and you greatly helped me :) ).

    Now I will try to pass this parameter into a session variable.

    I've another parameter to pass to get something different :

    I'm adaptating my gallery to mobile device. In that way, I've made a differenciation between mobile and desktop use of my gallery :
    - on desktop, each album shows on several pages of 12 images.
    - on mobile, each album shows on one page, containing all images and the user (wich is used to scroll down on the tactile screen), have all the images accessibles by scrolling down.
    Where my second parameter plays his game is when the user use the back button from the image page to go back to album. In mobile version, I need to send back my user to a certain portion of the album page instead of the top of the page. To make that, I've dynamically made anchors on each images (#ID1, #ID2, #ID3... #ID20...), and pass this parameter in the url. Then the link back head to : /portfolio/album/subalbum/#ID16 for exemple, and the viewport automatically come to the thumb of the picture the visitor just leave.
    It's the way I find to do that, but it may exists something simpler (I'm very new in the coding world and maybe have wrong ideas, but, it does work...)
    So if you have a better idea to do something like that, it's great. If no, no problem, I'll try to pass this parameter in a session too...

    Thank you again for your help
  • acrylian Administrator, Developer
    If you like to do different things on desktop/mobile you could for example have two different links and hide one on certain media query breakpoints.

    Alternatively if you need to do things servers side via PHP you could use hte mobileTheme plugin. The name is a bit misleading as you don't need to define a separate mobile theme at all. It also includes a framework named mobile_dectect you can use on your theme directly: http://mobiledetect.net

    There is also a filter hook to link generation that should be listed on our plugin tutorial. But maybe above ways are easier, at least to try first.
  • Thank you acrylian. I already use mobile_detect. It's fine :)

    I'm back after some trying with session variable.
    I've tried to replace my ?limit variable of the url with a session one. The problem is that I the variable limit is incremented for each image in the album (here is the code :)
    <?php $limit=1;
    while (next_image()):?>
    <?php printImageThumb(getAnnotatedImageTitle());?>
    <?php $limit++;
    endwhile;?>

    If I do the same thing with a session variable, only the last variable will be stored (ie if my album has 12 images, the session variable will be 12 for each image of the album), wich is logic as the variable is updated for each iteration of the loop...
    Is there a way to use session variable in that case? I'm not sure...
  • acrylian Administrator, Developer
    Pardon me that I maybe not fully understand what you are trying ;) Maybe the session is then not the right way. I thought you use the limit to jump back to a specific image id?
  • In fact, the limit parameter allow me to stop navigation (by hiding the navigation tools) when the visitor reach the 12th image of the last image album :)

    Maybe can I find something by storing an array in a session variable... I'll try to find.
  • acrylian Administrator, Developer
    So basically you just want to hide the page nav on mobile if you have more than 12 images? Then you could just use `getNumImages()` in combination with mobile detect and/or specific css to do so. Unless I still don't get it ;-)
  • I thought about using getNumImages, but it does not really do what I want. It gives me the total number of images.

    Is there something else to find a unique ID (instead of the name of the image file) for each image, such as a number that would be displayed in the order of the images inside the album?
    ie ID=1 for the latest image, ID=2 for the previous, ect.
    I think it does not exist, but if ever...
  • acrylian Administrator, Developer
    Such an id does exist:

    There is `$_zp_current_image->getIndex()` to get the index in the current order of the image array (so 0 is the first) of an album.
    In normal theme image context you can also use `imageNumber()`to get this number (here starting with 1).

    Also `$_zp_current_image->id` does contain the unique id of the database row entry of the image. So not ordered numbers naturally.

    http://www.zenphoto.org/news/zenphotos-global-variables
    http://www.zenphoto.org/news/zenphotos-object-model-framework
  • imageNumber() !!!
    :):):)

    Acrylian, you're my hero ;). (and I know, I should have searched more in that direction...)

    Thank you, it solves all my problems. No use of these dirty parameters in url now!
    Now I'll work on the url rewriting to obtain the .html at the end of my images urls.

    Thank you again for your great work. ZenPhoto is GREAT!
  • acrylian Administrator, Developer
    Glad I could help ;-)
    Now I'll work on the url rewriting to obtain the .html at the end of my images urls.
    There is an option for this already: Options > General > URL options > mod_rewrite suffix.
    This is only for the image.php page naturally, not for direct image urls as that would not make sense ;-)
  • Well, done for the html. Perfect.

    Just a last question about url rewriting.
    When I'm navigating on the gallery with a mobile device, for the reason I explained in my first post (I want user to get back on the album page, from the image page, at the level of the image thumb he just leave), I have an url of this form :

    /portfolio/album/subalbum/#ID14

    where ID14 is the name of my anchor where my link back point to.

    Can I remove it with url rewriting?

    Promise, that was my last question :)
  • acrylian Administrator, Developer
    No, because that #id in the urltells the browser to scroll to specific element with that "id" on loading the page. If you remove that it will not work anymore.

    Without you would have to use JS/jQuery to scroll to a specific element. But then you have the problem to know what that is since you have to transfer that info it somehow.
  • Thanks. That is what I was thinking.
    About using JS, I tought about it, I can do that now because I have the ID in album and the imagenumber() in image.php (wich correspond).

    But I think JS would be heavier than this little code, so I think I will conserve it like that.

    Thanks again for all Acrylian.
  • acrylian Administrator, Developer
    To scroll would probably be only a few lines jQuery. jQuery itself is loaded already anyway.
Sign In or Register to comment.