I'm currently building a gallery in Kirby and have an album page that effectively has two modes: 1) Gallery listing, showing all items. 2) Single Image. I'm passing in a GET
variable like so:
/gallery/album-name?p=03.jpg
What I really want is a URL like this:
/gallery/album-name/03.jpg
Kirby already does some url rewriting in its default .htaccess
file, like so:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
Which re-writes the urls from this /index.php/gallery/album-name?p=03.jpg
removing the index.php
part.
Now, I did think I could simply have it rewrite any URL that has a get variable like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([A-Za-z0-9-]+)?$ index.php?p=$1 [L]
But that didn't seem to work.
My question is this: Can this be done? And if so, will the GET
variable still be available to my script?
Many thanks!
My current full re-write rules
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
#//www. vs //
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
# block all files in the site folder from being accessed directly
RewriteRule ^site/(.*) error [R=301,L]
# block all files in the kirby folder from being accessed directly
RewriteRule ^kirby/(.*) error [R=301,L]
# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
# make gallery links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^gallery/(.*)/([A-Za-z0-9-]+\.jpg)?$ index.php?p=$2 [L]
# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>
This works for everything, but I get a 404 on (for example) this url: /gallery/my-gallery-name/01.jpg