Friendly URLs with querystring params for articles and galleries

Hi,

A little bit of an introduction: about 10 years ago I created a website using modx revolution for a non-profit sports club. Since creating it I only did CMS and package updates and sometimes small adjustments to templates/chunks. I haven’t worked with modx apart from that. Lately I have been doing some updates and want to make it near perfect in regards to SEO scores, lighthouse etc.

One of the issues I am having now is that pagination of news (articles) and image galleries (gallery) use query string parameters. I would like to make it so that the page number (for articles) and gallery photo album ID becomes part of the friendly URL eg. /news/2 rather than news?page=2.

I have found this topic:

I am now wondering what the best way is to achieve this. The topic mentioned above suggests using an extra or customizing the .htaccess file. Looking at the readme of the extra I am not sure if it is intended for my use case?
I am also unsure if customizing the .htaccess is the way to go.

Apart from the topic above I am struggling to find good resources, which I find weird because I don’t think my goal is unique. Can someone point me in the right direction?

Extras that have this functionality in MODX usually work as follows:

  • There is a plugin that runs on the event OnPageNotFound
  • In the plugin, the code checks if the beginning of the request URL path matches certain resource-aliases.
  • With $modx->sendForward(...) the request is redirected to the correct resource.

You could write such a plugin yourself. Here is some sample code:

You could use the extra CustomRequest, if you don’t want to code yourself.

Or use a RewriteRule in the .htaccess file (which I personally don’t like as it’s hard to debug).


Also, if you use pdoPage for the paging (part of the pdoTools extra), then I believe there is built-in option for friendly page URLs.

Thanks!

I have now solved it with CustomRequest for all paging setups as well as gallery, works like a charm :slight_smile:. Was really easy and and it’s just configuration, I suppose htaccess would have better performance, but this way it’s just configuration in modx which seems cleaner to me.