Announcement

#1 2020-05-26 11:53:57

J0nny
Member
2017-12-15
32

redirect using htaccess - solved

Hi all,

I had needed to do some permanant redirects to redirect visitors from an old gallery3 installation to my piwigo gallery, plus another set to redirect from an old piwigo album to a new album in the same installation. I didn't find any specific instructions and it took a long time to get it to work, so for the benefit of anyone trying to do the same thing I thought I would post the redirects that worked for me.

First the gallery 3 installation (which sits in a folder called gallery2 )  this was easy and I just created a htaccess file which I put in the gallery2 folder with the following lines in:-

Redirect 301 /gallery2/index.php/NRW/Gevelsberg /galerie/index.php?/category/66
Redirect 301 /gallery2/index.php/NRW/Neuss /galerie/index.php?/category/97
Redirect 301 /gallery2/index.php/NRW/Hattingen /galerie/index.php?/category/68
Redirect 301 /gallery2/index.php/NRW/Wuppertal /galerie/index.php?/category/70

Those lines simply redirect to the top level album. Due to the URL gallery3 used, this works out well because if somebody finds a link to a picture page , the above redirect puts them in the relevant album page so they are not completely lost. Just for a couple of popular pages, I redirected an individual photo page to the corresponding piwigo page as follows-

Redirect 301 /gallery2/index.php/NRW/koeln/Cologne_fb13372 /galerie/picture.php?/1870/category/71

When it came to redirecting from within piwgo the above method did not work because the piwigo URLs contain a query string ( have a ? question mark in them ). After much experimentation, I found the following worked-

RewriteEngine On
RewriteCond %{QUERY_STRING} ^/60/category/7$ [NC]
RewriteRule ^ https://www.webbaviation.de/galerie/pic … tegory/135 [R=301,L]
RewriteCond %{QUERY_STRING} ^/60$ [NC]
RewriteRule ^ https://www.webbaviation.de/galerie/pic … tegory/135 [R=301,L]
RewriteCond %{QUERY_STRING} ^/category/7$ [NC]
RewriteRule ^ https://www.webbaviation.de/galerie/ind … tegory/135 [NC,L,R]
RewriteCond %{QUERY_STRING} ^/61/category/8$ [NC]
RewriteRule ^ https://www.webbaviation.de/galerie/pic … tegory/134 [R=301,L]
RewriteCond %{QUERY_STRING} ^/61$ [NC]

This is very rough and ready, there are probably much more efficient ways of coding this, however I only needed to redirect a small number of pages and so this was sufficient. I redirected each photo twice, once for where it is shown with the album in the address ( catagory ) and once for where it is shown without the album. I dont make much use of tags and so ignored them and each image is just in one album. The destinatuion is always the version showing the album.


NB in the first case I did not use the RewriteEngine On however some users may need it. Obviously on my server the relevant apache modules are installed and configured.  In the second one I had to write the destination URL in full as I had an issue when I tried the abbreviated  version as top. The second set of rewrites were put on an htaccess file which was uploaded to my piwigo gallery folder  which is called galerie.

I hope the above will be useful to someone attempting the same thing. Disclaimer: don't use the above on anything valuable or important as I am just a Tog with little knowledge of coding, coding mistakes are likely.. The above both took a day to figure out by trial and error.

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact