Forum
Runway and .htaccess URL rewriting guidance
Howdy,
I have the following URLs as a result of list and detail (with optional category):
LISTINGS
/projects/
/projects/?cat=printdesign
DETAIL
/projects/?s=microsoft
/projects/?cat=printdesign&s=microsoft
My goal is to rewrite as follows:
LISTINGS
/projects/
/projects/printdesign/
DETAIL
/projects/microsoft/
/projects/printdesign/microsoft/
I am an .htaccess rewrite dunce so I have two main questions which hopefully some folks could guide me along with:
1) Before I go diving into custom rewrite rules, should I instead be leaning on Runway's 'routes'? If not, am I okay to add custom rules or is this not recommended as it could cause mayhem with Runway's routing?
2) As the category part of the path is optional, I am guessing that it would be hard to make a rewrite rule for /projects/microsoft/ as it will assume 'microsoft' is a category? If so, perhaps when no specific category is needed, it should be /projects/all/microsoft/?
Any help/guidance/RTFM welcomed.
Churz, Keir
Thanks @Robert, appreciated - your post and https://docs.grabaperch.com/runway/routing/ helped me along.
I have managed to get the categories working, but not the slug. Also, if I provide just
/projects/project-slug/
it, as I feared, assumesproject-slug
is a category.I also tried removing the category part of the routing, so just
/products/[slug]
but no dice either.Any further thoughts?
I guess the issue is that there's no difference between
and
as far as any dumb pattern matching the URL is concerned.
If you need to have that URL format you'll have to route them to the same page (as they will anyway) and query the CMS to find what sort of mode you should be in.
Yeah, I suspected such. I may simply use /all/ when no category is present.
That aside, any ideas why I am struggling to get just slug rewriting working?
E.g.
/projects/?s=microsoft
to/projects/microsoft
My route in page options is
projects/[slug]
and I am using the following list & detail code:It I go to
/projects/microsoft
, it is outputting the listing page so I suspect the slug part of the URL is not being rewritten to ?s=Thanks folks
try:
Ding ding ding! Thank you, that worked.
I will now go and play to see how to get categories involved either using /all/ or some internal logic.
Thanks both, very much appreciated - will post my final outcome.
Using Route: projects/[slug:s] ...
get value of ('s')
Without the :s (name) you could get the value as...
Thanks Robert - I will give that a go next.
In the meantime, I did manage to get it working by forcing /all as the default category:
...and...
Will report back if I succeed with your suggestion.
Dang, really useful to be able to use
perch_get([querystring_array])
but would still either need some logic to check different between/projects/category-slug/
and/projects/project-slug/
OR would need me to split the list and detail over two pages, e.g./projects/
and/projects-detail/
I reckon I'll stick with the
all/
solution for now and try this approach next time.Thank you so much for your help!