Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Bug (messy URLs): No error status if category does not exist
Pre-condition: I have to use messy URLs on a new TXP 4.4.1 website (don’t ask).
Update: I managed to get clean URLs working but the error still exists when using the messy URL below.
(Edit: Changed links to text because Google webmastertools is complaining :)
- TXP throws a correct 404 for ‘non existent sections’ like http://advokathamburg.de./index.php?s=enenemuh.
- TXP doesn’t throw a 404 for ‘non existent categories’ like http://advokathamburg.de./index.php?c=enenemuh.
- I did not check which other URL parameters are not caught with a 404.
- Note: The
txp:if_category
which I use is called (photos in the right sidebar) and delivers an empty category page with status 200. I’d prefer the 404 :)
- In clean URL mode on another website TXP delivers a correct 404 for non existent categories.
Sidenote: If I see it right the messy URL server only throws internal 404s for non-/index.php requests. Any idea how I could catch those 404s via .htaccess?
Update: Added to the Google repository code.google.com issue 127
Last edited by merz1 (2012-11-27 16:34:26)
Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML
Offline
Re: Bug (messy URLs): No error status if category does not exist
Try r3870.
Offline
#3 2012-07-14 20:41:56
- ax
- Plugin Author
- From: Germany
- Registered: 2009-08-19
- Posts: 165
Re: Bug (messy URLs): No error status if category does not exist
This change results in an 404 error when a there is a link category but no article category with the same name.
Consider this code block for a list of child link categories:
<txp:category_list wraptag="ul" break="" exclude='<txp:category type="link" />' type="link" parent='<txp:category />' children="0">
<li><txp:category title="1" link="1" /></li>
</txp:category_list>
A list which looks like this:
http://www.example.com/?c=.........&context=link
is generated by the above code, and it works ok Textpattern 4.4.1. But now a 404 is returned, although the link categories exist.
Offline
Re: Bug (messy URLs): No error status if category does not exist
That’s a good find Peter.
Looking at source, it seems that there has been a problem all along with the context code and the root cause isn’t actually in this change, but added checking just revealed it. There are few distinct issues:
First is that contexts are localized, and valid context values are set by translation strings. But l18n interface isn’t used when Textpattern builds links, or for that matter when overwriting values during URL routing. Rest of the code that generates those links use hard-coded values (link, article, file) which won’t be correct for anything else than default English translations.
Other issue is that context is picked up from an URL properly only when using clean URLs. In messy mode the code skips couple steps entirely. In messy mode context
is only used when ?s
or ?id
param is present in the URL. In other words, only when you are on a section page or on individual article page. Which is strange.
On any other page, the context is overwritten as hard-coded article
. Which is the wrong value too since the values are localized. Context validator (ValidContext()
) is then called once more, and it replaces all hard-coded tryouts with article. Guh.
Robert, Stef I don’t try to intrude with your work, but could it be correct place to rename some of those variables with more self-explanatory names or do tiny bit of clean up as page routing is concerned? The root cause to these mistakes could very well be in confusion of which variable is which and how the logic works in pretext().
Honestly, I can’t blame anyone placing code in wrong spots or missing conditions entirely in that function. No idea how you would make that more bit of clear, tho.
Last edited by Gocom (2012-07-14 22:50:03)
Offline
Re: Bug (messy URLs): No error status if category does not exist
Gocom wrote:
First is that contexts are localized
Which is a questionable design choice on its own, I think, as it allows translators to break existing URLs on third-party sites at any time in the future.
Offline
Re: Bug (messy URLs): No error status if category does not exist
wet wrote:
Which is a questionable design choice on its own, I think, as it allows translators to break existing URLs on third-party sites at any time in the future.
Yeah, I was following the convention adopted by /category URLs. For reasons best known to history., they’re localised so in French we have site.com/catégorie/whatever
. Go figure.
What impact would it have to break this and go back to dumb URLs throughout, or even just for context strings? Probably a massive compatibility issue unless we put in some sensible core rewrites… right?
Last edited by Bloke (2012-07-15 09:09:28)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Bug (messy URLs): No error status if category does not exist
Offline
#8 2012-07-15 11:24:41
- ax
- Plugin Author
- From: Germany
- Registered: 2009-08-19
- Posts: 165
Re: Bug (messy URLs): No error status if category does not exist
Gocom wrote:
… there has been a problem all along with the context code and the root cause isn’t actually in this change
This would explain other anomalies that occur occasionally with link categories. I used to simple create article categories by the same name as a workaround, and would recommend this to anybody encountering similar problems.
wet wrote:
Thanks wet, for not giving up on Textpattern. From this conversation I gather that this will be a tough one.
Offline
Re: Bug (messy URLs): No error status if category does not exist
Please try r4009.
Offline
Re: Bug (messy URLs): No error status if category does not exist
I run few very fast test, and for what I can tell things work well with r4009 as far as routing goes. I haven’t yet tested tags itself, but routing itself seems to work fantastically.
As preparations:
- I created total of 8 categories: article1, article2, image1, image2, link1, link2, file1 and file2. Each given the appropriate type.
- Created a section named home.
- Updated a default page template to contain just
<txp:category />
tag and assigned the template to the two sections default and home.
For tests, I then gone through the supported URL formats one by one. Results are (request => result):
- ?c=non-existing => 404
- ?c=article1 => article1
- ?c=article2&context=article => article2
- ?c=article2&context=invalid => article2
- ?c=link1 => 404
- ?c=link1&context=link => link1
- ?c=link2&context=article => 404
- ?s=home&c=article1 => article1
- ?s=home&c=link2&context=link => link2
- /category/image/image1 => image1
- /category/article/image2 => 404
- /category/file1 => 404
- /category/article1=> article1
- /category/invalid/article2 => article2
The results seem fine as routing is concerned. Both messy and clean URL modes are consistent too.
Last edited by Gocom (2012-07-25 23:44:46)
Offline
#11 2012-07-26 06:31:27
- ax
- Plugin Author
- From: Germany
- Registered: 2009-08-19
- Posts: 165
Re: Bug (messy URLs): No error status if category does not exist
wet wrote:
Please try r4009.
I can confirm that in the plain vanilla situation I get correct results for link categories, that is 404 with /?c=category
and a good result for /?c=category&context=link
. But the behaviour is quite different from revision #r3869, and actually it breaks my application. The reason for this is that with /?c=category&context=link
this revision does not enter the
<txp:if_category>
</txp:if_category>
code block. This explains why it works for me when the link category name also is listed among the article category names. Then the <txp:if_category>
block will be executed. But when I write: <txp:if_category type="link">
instead, it works! That looks phantastic indeed, everything is fine with my application now :))
Sorry for the many edits.
Last edited by ax (2012-07-26 07:03:01)
Offline
Re: Bug (messy URLs): No error status if category does not exist
ax wrote:
…when I write:
<txp:if_category type="link">
instead, it works!
Looks like we finally managed to live up to our own documentation.
Offline