Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2004-06-28 06:13:15
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
[plugin] [ORPHAN] zem_redirect
Hi,
Textpattern articles are currently reachable via several different URL paths. For example:
http://example.com/article/5/
http://example.com/article/5/article-title
http://example.com/article/5/old-article-title-before-i-renamed-it-to-something-shorter
External factors can multiply these (e.g. www.example.com vs. example.com).
This can cause problems with search engines and link aggregators, since they don’t have any way of knowing that all of these URLs represent the same page (as opposed to multiple pages with identical content).
txp:zem_redirect is designed to help reduce the problem a bit. It checks the URL used to fetch each article; if it doesn’t match the correct URL for the article (including the article-title and full hostname as specified in the Textpattern config), it’ll return a 301 Moved Permanently response to direct the user’s browser to the correct URL. It also works as a 404 handler for articles that don’t exist or are not visible.
Just plonk the tag <txp:zem_redirect /> at the top of your article page, and it’ll do the rest. It must be the very first tag on the page, before the doctype. It has no effect in messy URL mode, or on pages other than individual articles.
warning – if you’re already using URL rewriting or other clever redirection, there’s a chance this could cause circular redirects. Test carefully, and don’t say I didn’t warn ye.
http://vigilant.tv/documents/tp/zem_redirect-0.5.txt
z.
As this plugin is no longer supported we provide it here
YToxMDp7czo0OiJuYW1lIjtzOjEyOiJ6ZW1fcmVkaXJlY3QiO3M6NjoiYXV0aG9yIjtzOjExOiJBbGV4IFNoaWVscyI7czoxMDoiYXV0aG9yX3VyaSI7czoyNjoiaHR0cDovL3RocmVzaG9sZHN0YXRlLmNvbS8iO3M6NzoidmVyc2lvbiI7czo1OiIxLjIuMSI7czoxMToiZGVzY3JpcHRpb24iO3M6NTk6IlJlZGlyZWN0IFBybzogaGFuZGxlIGluY29ycmVjdCwgb3V0ZGF0ZWQgYW5kIGR1cGxpY2F0ZSBVUkxzIjtzOjQ6ImhlbHAiO3M6Mjk3OiI8cD5UaGlzIHBsdWctaW4ncyBoZWxwIGRvY3VtZW50cyBhcmUgYXZhaWxhYmxlIHRvIHBheWluZ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lvbiBzcGVjaWZpZWQnKTsNCgl9DQoNCgkkYWN0dWFsX2hvc3QgPSBzZXJ2ZXJTZXQoIkhUVFBfSE9TVCIpOw0KCSRhY3R1YWxfcGF0aCA9ICgkdGVzdCAhPT0gMCA/ICR0ZXN0IDogJHByZXRleHRbJ3JlcXVlc3RfdXJpJ10pOw0KCSRhY3R1YWxfdXJsID0gJ2h0dHA6Ly8nLiRhY3R1YWxfaG9zdC4kYWN0dWFsX3BhdGg7DQoNCglpZiAoJGRlc3QgYW5kICRkZXN0ICE9ICRhY3R1YWxfdXJsKSB7DQoJCSRzdGF0dXMgPSAoJHR5cGUgPT0gJzMwMScgPyAnMzAxIE1vdmVkIFBlcm1hbmVudGx5JyA6ICczMDIgRm91bmQnKTsNCgkJcmV0dXJuIHplbV9yZWRpcmVjdF9zZW5kX2hlYWRlcnMoJGRlc3QsICRzdGF0dXMsICRkZWJ1Zyk7DQoJfQ0KDQp9DQoiO3M6NDoidHlwZSI7czoxOiIwIjtzOjU6Im9yZGVyIjtzOjE6IjUiO3M6MzoibWQ1IjtzOjMyOiJkM2UzNjRiZTY2NWNkODNjNTIxZWFmODdiMjQ3NDMyZiI7fQ==
Last edited by zem (2004-07-10 02:53:25)
Alex
Offline
Re: [plugin] [ORPHAN] zem_redirect
Hi zem,
thank you very much. That sounds like a great plugin. :)
I’ll definitely give it a try.
Offline
Re: [plugin] [ORPHAN] zem_redirect
This is a great idea for a plugin. I can’t wait to try it out as well.
Offline
#4 2004-06-28 21:12:54
- DougBTX
- Archived Plugin Author
- Registered: 2004-05-23
- Posts: 22
Re: [plugin] [ORPHAN] zem_redirect
belle
Offline
Re: [plugin] [ORPHAN] zem_redirect
works great! no more ‘redirect 301’! thanks, zem!
Offline
#6 2004-07-04 01:14:50
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_redirect
There’s a new version up:
http://vigilant.tv/documents/tp/zem_redirect-0.2.txt
Changes in this version:
- Now supports the article URL title feature
- Works with section and default pages (adds a trailing slash if neccesary, etc)
Last edited by zem (2004-07-04 01:15:05)
Alex
Offline
#7 2004-07-04 01:41:40
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_redirect
And again:
http://vigilant.tv/documents/tp/zem_redirect-0.3.txt
Changes:
- Returns a 404 response for non-existant or unpublished articles
- Calls exit() immediately after redirect or 404, to stop further output
Alex
Offline
Re: [plugin] [ORPHAN] zem_redirect
I can’t seem to get it to work. The thing keeps on redirecting itself whenever i try to access an individual article. Any ideas?
Offline
Re: [plugin] [ORPHAN] zem_redirect
Excellent plugin, zem. You might want consider letting people specify an article number (through a plugin parameter, preferably) containing an error message and redirect to it in case of a 404.
Also, you should check for ‘query’ index in a way that doesn’t generate the ‘Undefined indexes’ notice, e. g.
if (!empty($parts["query"]))
Who’s gonna textdrive you home tonight?
Offline
#10 2004-07-05 02:11:49
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: [plugin] [ORPHAN] zem_redirect
ThrokFeroth, do you have any other URL redirection or rewriting configured? Is your “web domain” setting correct?
Mamash – thanks for the suggestions. I’ll put together a new version that supports a few attributes to control its behaviour.
Alex
Offline
Re: [plugin] [ORPHAN] zem_redirect
Firstly, I use my default template for my Thoughts section. However if I add the redirect, the thing will redirect me to http://relativemind.net/default which is not a section at all, but merely the page template name.
Next, if I create a template called Thoughts and add the redirect, the thing exceeds redirection limits everytime I try to access the individual article.
Well, I do have a redirect that redirects all who access http://www.relativemind.net to http://relativemind.net. Is this the thing which causes it not to work?
Offline
Re: [plugin] [ORPHAN] zem_redirect
i had the same problem with it constantly appending /default/ to the URL. but i’m not really worried about catching 404s anyway, so i won’t worry about it right now.
Listen to Kenneth
Offline