Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Clean URLs combining section and category on a single request
Hello,
I would like you know if it is possible to mix sections and categories on a single petition and still have a clean URL.
I will explain that. Using <txp:category name="CAT1" section="SEC2" />
tag we are telling that we want those articles on section SEC2 that fall under category CAT1, ok, the URL for that would be: http://host/SEC2/?c=CAT1
, and that isn’t very clean so to speak.
I can only get clean URLs with <txp:category />
when in default section and being no section specified inside the tag: <txp:category name="CAT1" />
or <txp:category name="CAT1" section="" />
. That would produce: http://host/category/CAT1
.
So the question is: is it possible to call a list of articles inside certain section falling under certain category and still have a clean URL?
Thank you for reading and thanks in advance for you help.
Best regards,
Zeles.
Offline
Re: Clean URLs combining section and category on a single request
You could create your own re-write rules for each section that has it’s own category, but it is not specifically built in to textpattern to do so.
Although, that would be nice if we could do something like url.com/section/category/category_name automagically.
Proud Canadian. Toronto Locksmith , Actualize Consulting
Offline
Re: Clean URLs combining section and category on a single request
Hello, 1beb. Thanks for your reply.
You could create your own re-write rules for each section that has it’s own category, but it is not specifically built in to textpattern to do so.
I was rather starting to think so. Well, let’s get cracking. I solved it (that means: it hasn’t blown up yet) with a few changes both in the .htaccess file and my page/form templates.
- Line to add to .htaccess:
RewriteRule ^([^/]+)/category/([^/]+)/?$ index.php?s=$1&c=$2 [L]
(Those <sup>
and </sup>
are both carets; textile is changing them.)
The string category can be whatever you like most: categoria, cat… but make sure it matches the href content of your <a>
links.
- Then we have to tweak the anchors that link to a category in our page or form templates:
Before: <txp:category title="1" link=1" section="SEC" name="CAT" />
After: <a href="<txp:site_url /><txp:section name="SEC"/>/category/<txp:category name="CAT" />"><txp:category title="1" name="CAT" /></a>
Note that <txp:section />
without attributes gets replaced by the article section when called from an article form, that means that you can combine it with <txp:category1 />
to get a link to the article’s category: <a href="<txp:site_url /><txp:section />/category/<txp:category1 />"><txp:category1 title="1" /></a>
Although, that would be nice if we could do something like url.com/section/category/category_name automagically.
Indeed.
Regards,
Zeles.
Offline