Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Let Textpattern accept URLs with trailing slash?
Hi,
I have the URL scheme /title but I can only access the articles when using /section/title.
Textpattern doesn’t show an empty article but “not found” message.
I don’t understand why that is. The txp:article tag should realize that the article is part of the section, even without the URL.
Edited: Rewrite rule adds trailing slash which isn’t supported by default. See below. Still need a solution.
Thank you,
Alex
(Edit: Thread title changed in order to address the problem better.)
Last edited by ar (2021-01-20 20:02:26)
Offline
Offline
Re: Let Textpattern accept URLs with trailing slash?
Hi Alex, Article URL patterns are now defined in two places.
- Admin>Preferences>Site
- Presentation>Sections>[Click on the name of the section].
Can you check if the Article URL pattern in the section in question, is indeed set to /title?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Let Textpattern accept URLs with trailing slash?
Wow, I just tried it with a Textpattern demo site and realized that is indeed not possible to reach the title-only articles with a trailing slash:
https://release-demo.textpattern.co/welcome-to-your-site
vs.
https://release-demo.textpattern.co/welcome-to-your-site/
I do indeed have a .htaccess rewrite rule that adds a trailing slash to all URLs.
I am much relieved to know that this seems to be the problem.
Is there a way to let Textpattern accept the trailing slash?
Thank you very much :-)
Alexander
PS: Not a solution, but a related thread.
PPS: URL scheme /section/title/ seems to work, see for example:
https://release-demo.textpattern.co/artikel/welcome-to-your-site/
???
Last edited by ar (2021-01-20 20:05:55)
Offline
Re: Let Textpattern accept URLs with trailing slash?
The lack of displaying a title with a trailing “/” is most likley a bug. I often use the slash for various sites and they work just fine. Like this one for e.g.:
https://forum.textpattern.com/viewtopic.php?pid=328263#p328263/
…. texted postive
Offline
Re: Let Textpattern accept URLs with trailing slash?
In a way you are right, I think that this cannot be intended behavior as well. However, your example has a number sign in it. After # you can put whatever you want, it won’t (as far as I know) be parsed on the server-side.
Offline
Re: Let Textpattern accept URLs with trailing slash?
ar wrote #328265:
In a way you are right, I think that this cannot be intended behavior as well. However, your example has a number sign in it. After # you can put whatever you want, it won’t (as far as I know) be parsed on the server-side.
this is a Txp site: https://bicilogic.com/article/three-oaks/
see this discussion
…. texted postive
Offline
Re: Let Textpattern accept URLs with trailing slash?
That’s exactly what I haved witnessed. I guess /article/ is the section (in your example), and therefore using a trailing slash works. Without section (/title/ only) it doesn’t. So indeed this seems to be a bug.
Last edited by ar (2021-01-20 21:27:45)
Offline
Re: Let Textpattern accept URLs with trailing slash?
ar wrote #328263:
I do indeed have a .htaccess rewrite rule that adds a trailing slash to all URLs.
For what purpose?
Is there a way to let Textpattern accept the trailing slash?
It does, but you certainly mean ‘for individual articles’? What would be sections URLs in title_only mode?
PPS: URL scheme /section/title/ seems to work, see for example:
Yes, because there is no ambiguity between /section/ and /section/title/ URLs.
Offline
Re: Let Textpattern accept URLs with trailing slash?
The purpose is consistency: I redirect all http to https, all www to non-www, and adding trailing slashes when they’re not there.
Why should there be no ambiguity when /title (without trailing slash) has the same name as /section?
I don’t need sections in a “public” way, only implicit (if at all) in order to use specific colors for headlines for each “section” (via body class=”<txp:section />”). But that is nothing a visitor should be bothered with. <txp:article /> knows the section, as well as forms and pages, so I don’t see a problem there.
That is my example: (…)
Right know I have to use the section. Since I deleted my (too) many sections yesterday and only have two right now (psychotherapie, impressum) I hand over the different h1 colors (headlines) via categories right now.
However, I only want one section, in fact, because it’s a hassle to create and manage them. I just want to create an article and assign a color. Then manually link to it.
Therefore I would like to remove the sections in the URL scheme because the website is small enough to keep track of the article’s custom url’s.
Last edited by ar (2021-01-20 23:13:28)
Offline
Re: Let Textpattern accept URLs with trailing slash?
ar wrote #328270:
The purpose is consistency
It already is consistent. If a URL represents an article it has no trailing slash. If it represents a landing page, it has one.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Let Textpattern accept URLs with trailing slash?
Further details:
My .htaccess:
RewriteRule ^!([^/\.]+)/?$ https://xxx.de/?id=$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^xxx\.de$
RewriteRule ^(.*)$ https://xxx.de/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [R=301,L]
My sections:
default, front page, imprint, psychotherapy
My default form:
<h1 class=”<txp:category1 />”><txp:title /></h1>
<txp:body />
My default page:
<txp:if_section name=“default”>
<txp:article id=“2” form=“default” status=“4” />
<txp:else />
<txp:if_article_list>
<txp:if_section name=“psychotherapie”><txp:article_custom category=“overview” section=“psychotherapie” form=“default” sort=“Posted desc” status=“4” /></txp:if_section>
<txp:if_section name=“impressum”><txp:article_custom category=“overview” section=“impressum” form=“default” sort=“Posted desc” status=“4” /></txp:if_section>
<txp:else />
<txp:article form=“default” status=“4” />
</txp:if_article_list>
</txp:if_section>
Last edited by ar (2021-01-20 23:14:10)
Offline
Re: Let Textpattern accept URLs with trailing slash?
Bloke wrote #328271:
It already is consistent. If a URL represents an article it has no trailing slash. If it represents a landing page, it has one.
What do you mean by landing page?
That doesn’t solve my problem, however :-(
Offline
Re: Let Textpattern accept URLs with trailing slash?
ar wrote #328270:
I don’t need sections in a “public” way, only implicit (if at all) in order to use specific colors for headlines for each “section”
Fine, but your use case isn’t the only use case in Textpattern. We need to cater for other people that do require sections in the URL schemes too. We provide many schemes to let people choose how they want each section to behave. And a fallback scheme in prefs.
Without that telltale trailing slash, we have no way of knowing (without trial and error, which is computationally a little more expensive and therefore slower) whether /products is an article called ‘products’ in a section, or the section landing page for /products.
If you have both in your site, which should Textpattern choose when faced with that URL?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Let Textpattern accept URLs with trailing slash?
ar wrote #328270:
The purpose is consistency: I redirect all http to https, all www to non-www, and adding trailing slashes when they’re not there.
There is a difference between rewrite and redirect. You should be able to redirect browsers to slashed URLs, but then rewrite /title/ as /title to make txp understand that it is not a section.
Why should there be no ambiguity when /title (without trailing slash) has the same name as /section? I don’t need sections in a “public” way
You don’t, but other users do. How would they tell /about/ section from /about/ article if both exist?
This said, I agree txp URL schemes are not flexible enough and we should introduce custom schemes one day.
Offline