Single image view: how to change URL?

Hello, I’m setting up a gallery in a fresh install of MODX3. So far, so good! This is my first time using MoreGallery which may become obvious by my questions. :wink:

What I’d like to accomplish is a different URL for the single image view. Out of the box it’s:
example.com/gallery.html?iid=24

Ideally I’d like:
example.com/gallery/alias-dynamically-generated-from-the-image-name

Or:
example.com/gallery.html?customparam=value-dynamically-generated-from-the-image-name

Or, as a last resort, a manually created alias for each image.

Possible? I don’t care if it’s an actual new resource for each image (although that would be fine too), or a way of masking the params. I’d just like to get the image title into the URL for SEO, etc.in the easiest way possible.

Also, what does the Link (or Resource ID) field in the image details do? I find I have not been able to make it effect anything. Probably just me. :sweat_smile:

Bumping this as I have figured out a compromise for the ugly single image view URL – by tacking on the filename as an additional parameter and making sure all images are named in a human readable way.

But, I am still not understanding what the Link (or Resource ID) field in the image details does? Can anyone shed some light?

MoreGallery does need the iid = <id of image>, and does not have any unique alias to reference instead, but you could do something things with rewrite.

For example you could use URLs like example.com/gallery/24-dynamic-created-from-name, which a rewrite rule internally rewrites to example.com/gallery/?iid=24, discarding the alias.

Untested, but that would look something like this on Apache servers (.htaccess):

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^gallery/(\d+)\-(.*)$ index.php?q=gallery&iid=$1 [QSA,L]

The first (capture) block with \d+ matches 1 or more numbers, followed by a -, and anything else after that (.*). It then sends the request to MODX for the alias gallery with the iid parameter set to that first capture block.

In your imageTpl chunks, you’d need to make the URL yourself, with something like…

<a href="[[~[[+resource.id]]]][[+id]]-[[+name:filterPathSegment]]">..</a>

(If your resource is not marked as a container, add a slash in between.)

But, I am still not understanding what the Link (or Resource ID) field in the image details does? Can anyone shed some light?

That’s just another field you can optionally fill. It doesn’t handle the link to the image.

It doesn’t look like it’s actually rendered anywhere by default, but you could (for example on the detail page) add <a href="[[+url]]">Source</a> to add a reference link to where the image originated (think copyright holder).

Thanks for the explanation of the url field. Makes sense now.

I think I didn’t explain myself well concerning the URL for a single image. The default URL out of the box IS already example.com/gallery/?iid=24 , and I’m hoping to turn that into something more human (and robot) readable. But possibly using a rewrite rule is still the way to approach this. I’m on MODX Cloud so would be a Nginx rule…