MODX Community

Query param as a part of SEO url?

Greetings. I was wondering if I could use a query param as a part of SEO url, e.g., I want transform to, I’ve tried adding this to .htaccess:
RewriteRule ^(.)/(.)$ index.php?q=$1&type=$2 [L,QSA]

Actually it’s the latest version of rewrite rule I’ve tried, I’ve also tried several others like this one:
RewriteRule ^([^/]*)/catalog/wine/$ /catalog/wine?type=$1 [L]

But none of them worked.


MODX 2.7.2, Apache 2.4.

Maybe you can use the extra CustomRequest for this, instead of trying to change the .htaccess.

Yes, CustomRequest or another custom plugin at the Event onPageNotFound, if CustomRequest doesn’t fit your needs.

Have you tried it like this?

RewriteRule ^/catalog/wine/(.*)$ index.php?q=/catalog/wine/&type=$1 [L]

Wether it’s more suitable to manage from MODX (CustomRequest or other plugin) or htaccess is debatable depending on the use case. The htaccess approach is probably a little more performant at the trade-off of needing to manage it in a file.

@markh, I think the op wants to do the opposite of what your rule does.

This is a little funky, but it works according to this tester:

RewriteCond %{REQUEST_URI} catalog/wine
RewriteCond %{QUERY_STRING} (?:type=)([a-zA-Z]+).*$
RewriteRule (.*) catalog/wine/%1?

You’ll have to adjust the [a-zA-Z] if your wine types contain other characters.

Thanks for the answers guys!

@halftrainedharry, I’ve tried it but with this extension I can only do a redirection from to which is not what I’ve wanted (this query param rewriting is for SEO purposes), I was wondering if I’m doing something wrong? I’ve added ‘catalog/wine/red’ to the ‘Alias Path’ and pointed it to my Red Wines resource, it does the redirect but I still can see the ‘catalog/wine?type=red’ in the address bar.

@bobray, that’s what I’ve wanted, but for some reason it’s not working, the url’s not being rewritten.

my question is, where are this links like
coming from? Why do you not just generate them like

and then use CustomRequest for redirecting

The problem is that there are some quirky snippets for filtering products that need to be modified to work with new urls, so I wanted to go with a quick rewriting solution, well, seems that I’ll need to do a bit of R&D.

seems, what you want, is a plugin or a snippet, which you place on that redirects for example to

I definitely tested that .htaccess section. Do you have non-alphanumeric characters or spaces in your type=... section? Have you tried moving the rules above the MODX FURL section (but after the RewriteBase and engine on statements)?

If it’s just one page, bruno17’s suggestion is probably easier.