![]() |
|
Clean URLs for tags - a simple hack - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: Clean URLs for tags - a simple hack (/thread-2041.html) |
Clean URLs for tags - a simple hack - misterbrandt - 2008-01-06 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: (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: SEE ALSO: hack in template-functions.php - FUNCTION "getSearchURL" -- insert 4 lines starting at line 1967RewriteRule ^tags/(.*) index.php?p=search&searchfields=4&words=$1 [L,QSA] ` and I added 4 new lines at the start of the if ( !empty($words) && empty($dates) && $fields==SEARCH_TAGS && getOption('mod_rewrite') ) { // 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... Clean URLs for tags - a simple hack - acrylian - 2008-01-07 Good idea, we simply forgot rules for the tag search. I think we will implement that. Clean URLs for tags - a simple hack - acrylian - 2008-01-07 I took a deeper look to your hack. I reworked it so that it fits our general search paths which follows the zp custom page path like 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. Clean URLs for tags - a simple hack - misterbrandt - 2008-01-08 acrylian, good point about path consistency. I was actually inspired by this forum comment, which I forgot to reference in my initial post. So I just aped that URL structure. Clean URLs for tags - a simple hack - steffen - 2008-01-09 After updating to the most recent nightly build, the archive does not work anymore. The cause is related to "Changeset 1030". A click on the date link leads to an 404 page. Before I did the update, the url looks like this: Regards, Clean URLs for tags - a simple hack - acrylian - 2008-01-09 Right, if mod_rewrite is enabled the path should look like that. That's what I added. Probably you need to update you htaccess file with the new rewrite rules. The file should be included in the nightly build (probably invisible on your system). Clean URLs for tags - a simple hack - steffen - 2008-01-09 I also copied your .htaccess file from the (latest) nightly build. Since my gallery is not installed in /zenphoto, I had to change the RewriteBase like this: 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. Clean URLs for tags - a simple hack - acrylian - 2008-01-09 Strange, it works for me. Only updating template functions.php without the new htaccess can't work. Clean URLs for tags - a simple hack - steffen - 2008-01-09 What I found out is, that the rewrite rule works for tags, but not for the archive. You can have a look on my temporary site: www.synnatschke.com/gallery 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. Clean URLs for tags - a simple hack - acrylian - 2008-01-09 Could you please post your htaccess file? Seems that there is something missing since the normal path Clean URLs for tags - a simple hack - steffen - 2008-01-09 Sure! Here it comes... htaccess file for zenphotoNOTE: Change the RewriteBase below to the absolute path to your zenphoto directory.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] RewriteRule index.php$ index.php [L,QSA] Rewrite rule addtion for seachRewriteRule ^page/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?p=$1&words=$2 [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 ^(.)/image/(thumb|[0-9]{1,4})/([^/\]+)$ zp-core/i.php?a=$1&i=$3&s=$2 [L,QSA] Catch-all - everything else gets handled in PHP for compatibility.RewriteRule ^(.*)/?$ index.php?album=$1 [L,QSA] Clean URLs for tags - a simple hack - sbillard - 2008-01-09 acrylian: What does not work is the link generated when you click on a date in the archive. What I get for a url is:
This gives the This is with the nightly build .htaccess and having run setup. (All other mod_rewrite stuff that I have tried is workign.) Clean URLs for tags - a simple hack - acrylian - 2008-01-09 Steffen: We or more exactly sbillard figured it out. You need to change the archives rules a little to 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. Clean URLs for tags - a simple hack - steffen - 2008-01-09 Thank you for your support! Clean URLs for tags - a simple hack - steffen - 2008-01-10 The bug fix (htaccess) you released last night works only on the first page. 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). Clean URLs for tags - a simple hack - acrylian - 2008-01-10 Could you please stop reporting bugs...:-)) You are right, there are two lines reversed in the htaccess: That should be:
Regarding the images per page behaviour please look at this thread: http://www.zenphoto.org/support/topic.php?id=1911&replies=5 |