I haven't seen this addressed previously. Please let me know if it has.
I love the addition of tagging (and someday maybe a normalized database for them
), but I hate the URLs. So, I have a simple hack to make this:
`
http://elbedesign.com/zenphoto/index.php?p=search&searchfields=4&words=sometag`look like this:
`
http://elbedesign.com/zenphoto/tags/sometag`(this hack obviously requires that mod_rewrite is enabled. Well, I check to ensure that it is, so you can implement this hack on your site, but it won't do anything unless your server can support it (and zenphoto is configured to enable mod_rewrite)
I added these lines to the .htaccess:
` #### Rewrite rule for tags clean URL
#### SEE ALSO: hack in template-functions.php - FUNCTION "getSearchURL" -- insert 4 lines starting at line 1967 ####
RewriteRule ^tags/(.*) index.php?p=search&searchfields=4&words=$1 [L,QSA]
`
(You have to add this rewrite rule ABOVE the "catch-all" rule)
and I added 4 new lines at the start of the `getSearchURL` function in `template-functions.php` (inserted lines start at line 1967 in release 1.1.3)
`function getSearchURL($words, $dates, $fields=0) {
if ( !empty($words) && empty($dates) && $fields==SEARCH_TAGS && getOption('mod_rewrite') ) { // elbe added (hack for clean tags URL)
// if request is for a "tags" url AND mod_rewrite is enabled, give them a clean /tags/ URL // elbe added (hack for clean tags URL)
return WEBPATH."/tags/".$words; // elbe added (hack for clean tags URL)
} // elbe added (hack for clean tags URL)
$url = WEBPATH."/index.php?p=search";
if($fields != 0) { $url .= "&searchfields=$fields"; }
if (!empty($words)) { $url .= "&words=$words"; }
if (!empty($dates)) { $url .= "&date=$dates"; }
return $url;
}
`
I can make the hacked versions of these files available for download if necessary, but it is a pretty easy edit (and I don't really trust myself to update the hack with every point release).
All standard disclaimers apply -- make backups, hack at your own risk, I cannot be held responsible for any unforseen breakage. but it works on my test site...
Comments
Additionally I have added mod_rewrite rules for result pagination (that you maybe forgot) and for the archive date search too. Both needed a little more tweaking that just getSearchURL.
I already sent it to my fellow developers for testing, so probably that will be in one of the next svns.
http://www.domain.com/gallery/index.php?p=search&date=2008-01
after update:
http://www.domain.com/gallery/page/search/archive/2008-01
Regards,
Steffen
RewriteBase /zenphoto --> to RewriteBase /gallery
The new "clean URLs" does not work for me. I only get 404 pages. If I update just the template-functions.php and keep the older .htacces, I get the following error message:
Zenphoto Error: the requested object was not found. Please go back and try again.
Did you run setup.php after upgrading (that should set the rewritebase automatically)? Does archive work with disabled mod_rewrite?
If you click on the tag "sandstone", you will find all the related pictures. But if you switch to the archive: http://www.synnatschke.com/gallery/?p=archive and click on "January (6)", you will get an error message.
# htaccess file for zenphoto
# NOTE: Change the RewriteBase below to the absolute path to your zenphoto directory.
<IfModule mod_rewrite.c>
RewriteEngine On
#### !!! Change this to the web path (eg: http://www.yourwebsite.com/photos --> /photos) !!!
RewriteBase /gallery
####
RewriteRule ^admin/?$ zp-core/admin.php [R,L]
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
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 seach
RewriteRule ^page/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_]+)/?$ index.php?p=$1&words=$2 [L,QSA]
RewriteRule ^page/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_]+)/([0-9]+)/?$ index.php?p=$1&words=$2&page=$3 [L,QSA]
#### Rewrite rule addtion for archive-/date-search (needed to be separarted because of the same structur)
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\-_]+)/archive/([A-Za-z0-9\-_]+)/?$ index.php?p=$1&date=$2 [L,QSA]
RewriteRule ^page/([A-Za-z0-9\-_]+)/archive/([A-Za-z0-9\-_]+)/([0-9]+)/?$ index.php?p=$1&date=$2&page=$3 [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>
What does not work is the link generated when you click on a date in the archive. What I get for a url is:
`http://testalbum.sbillard.org/page/search/archive/2003-07`
This gives the `Zenphoto Error: the requested object was not found. Please go back and try again. ` error message.
This is with the nightly build .htaccess and having run setup. (All other mod_rewrite stuff that I have tried is workign.)
`RewriteRule ^page/([A-Za-z0-9-_]+)/archive/(.*)/?$ index.php?p=$1&date=$2 [L,QSA]
RewriteRule ^page/([A-Za-z0-9-_]+)/archive/(.*)/([0-9]+)/?$ index.php?p=$1&date=$2&page=$3 [L,QSA]`
It's in the next svn, too.
In my archive, I have 24 images for 1 month. 18 of them are shown on the first page, the other ones should be visible on the second page, but they dont. With mod_rewrite "on", I get the error "Sorry, no image matches. Try refining your search.". If I don't use mod_rewrite, I also get the second page with images. For verification, please see: http://www.synnatschke.com/gallery/page/search/archive/2008-01
Just another strange thing: I set the option "Image per page" to 15, which does not work properly, because I get 18 images on 1 page (see link above).
' RewriteRule ^page/([A-Za-z0-9\-_]+)/archive/(.*)/?$ index.php?p=$1&date=$2 [L,QSA]
RewriteRule ^page/([A-Za-z0-9\-_]+)/archive/(.*)/([0-9]+)/?$ index.php?p=$1&date=$2&page=$3 [L,QSA] `
That should be:
`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]
`
Sorry.
Regarding the images per page behaviour please look at this thread: http://www.zenphoto.org/support/topic.php?id=1911&replies=5