Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-07-28 22:06:21

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

clean urls with pagination htaccess question

I’ve got Oleg’s etc_pagination set up to paginate an article_custom list pretty much according to his instructions (very useful btw) but want to have a clean url structure and rewrite that using htaccess.

What I want to achieve is:

/articles --> show normal article list
/articles/2 --> show next paginated page of article list 
/articles/category/cat-name --> show article list filtered by category
/articles/category/cat-name/2 --> show next page of article list filtered by category

Currently I have a working solution, save for a glitch with the last rule which I think is interfering with links to the root of subfolders that are not managed by txp:

RewriteRule ^(.*)/category/(.*)(/([0-9]{1,3})?)$ index.php?s=$1&c=$2&page=$4 [L]
RewriteRule ^(.*)/category/(.*)$ index.php?s=$1&c=$2 [L]
RewriteRule ^(.*)(/([0-9]{1,3})?)$ index.php?s=$1&page=$3 [L]

I tried numerous experiments and different groupings but wasn’t able to make one rule that worked for all cases. Can this be optimised into a one-liner that doesn’t affect {section}/?

(BTW: For a reason too long to explain here, it has to run in the /articles/ section and not on the homepage so the standard txp:article tag is not an option here).


TXP Builders – finely-crafted code, design and txp

Offline

#2 2015-07-28 23:23:42

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: clean urls with pagination htaccess question

Hi jakob!

jakob wrote #293790:

Currently I have a working solution, save for a glitch with the last rule which I think is interfering with links to the root of subfolders that are not managed by txp:

Being that you are applying the rules to the articles section, you may want to replace ^(.*) with ^articles directly. Of course, this could make the rules a bit less “portable”, but they may not interfere with sections for which rewrite rules shouldn’t be applied. In case you have more than one TXP section that has to have these set of rules applies, you could “whitelist” them as this ^(articles|blog|some-section).

I tried numerous experiments and different groupings but wasn’t able to make one rule that worked for all cases. Can this be optimised into a one-liner that doesn’t affect {section}/?

I don’t think these set of rules could be condensed on just one-liner to rule them all, as the substitution part is different for each rule. Also, it may not be desirable from a code readability POV.

(BTW: For a reason too long to explain here, it has to run in the /articles/ section and not on the homepage so the standard txp:article tag is not an option here).

I didn’t understand this addendum.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2015-07-29 02:12:47

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: clean urls with pagination htaccess question

I don’t know if this will help or not but you might try looking at what I did to create my date-based archives and the accompanying plugin.

I’m thinking if you can’t get Textpattern to do what you want by default you might be able to do it through code in the page template.

Offline

#4 2015-07-29 03:07:25

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: clean urls with pagination htaccess question

Hi Michael

Interesting your plugin.

Additionally: This URL produces an error.

Offline

#5 2015-07-29 03:54:58

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: clean urls with pagination htaccess question

GugUser wrote #293794:

Hi Michael

Interesting your plugin.

Additionally: This URL produces an error.

I was experimenting with a plugin that never worked quite like I intended. Fixed it by removing the code.

Offline

#6 2015-07-29 04:54:54

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: clean urls with pagination htaccess question

Hi Michael, perhaps your date based archives would be a nice tutorial for TXP Tips?

Offline

#7 2015-07-29 10:42:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: clean urls with pagination htaccess question

Thanks Julián,

I don’t think these set of rules could be condensed on just one-liner

I had tried various attempts at making (/category)? an optional element of the url, and nearly got it working, but there was always some edge case not quite covered. Then smoke started emitting from my brain, and I decided I should ask the experts :-)

(BTW: For a reason too long to explain here, it has to run in the /articles/ section and not on the homepage so the standard txp:article tag is not an option here)

I didn’t understand this addendum.

I meant using the normal txp:article tag where /category/cat-name is covered normally isn’t an option here because the articles section of the site lists txp-articles from a whole host of other sections.

Thanks again!


TXP Builders – finely-crafted code, design and txp

Offline

#8 2015-07-29 11:26:41

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: clean urls with pagination htaccess question

jstubbs wrote #293796:

Hi Michael, perhaps your date based archives would be a nice tutorial for TXP Tips?

I will write it up and get it you as soon as I have time.

Offline

Board footer

Powered by FluxBB