Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Simple redirect from one article to another
I’ve recently used the URL-only title to change the URL of an article to make it shorter. Want people going to the old URL to be redirected to the new url without resorting to something heavy like Redirect Pro. Any ideas?
Yes, I have tried turning it off and on.
Offline
Re: Simple redirect from one article to another
Uhm.
The not-so-elegant way uses a meta redirect tag within the body of the old article.
(not recommended as used a lot by spammers)
The more elegant (and search engine friendly) way works by creating a 301 compatible redirect within your .htaccess file. See more info by searching 301 redirect htaccess
Or see a collection of techniques here.
Last edited by jayrope (2011-06-08 16:42:42)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: Simple redirect from one article to another
Thanks!
But then the question is, is there any way to do it at the textpattern/article level, without having to go in and modify page templates, etc just for this one case??
Yes, I have tried turning it off and on.
Offline
Re: Simple redirect from one article to another
For instance you could make a new custom field named “redirect” first.
Then make a form (type should be misc) called redirect
<txp:if_individual_article><txp:if_custom_field name="redirect">
<txp:php>
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: <txp:custom_field name="redirect" />");
</txp:php>
</txp:if_custom_field></txp:if_individual_article>
You’d add the output of this form at the absolute top (importat) of your page template.
<txp:output_form form="redirect" />
As soon as you put the URL of a new article in the respective custom field of the corresponding old article this should automatically work. (sorrry, had to edit this post…)
Hope it helps.
Last edited by jayrope (2011-06-08 17:36:56)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: Simple redirect from one article to another
Hmm… that seems fits the bill exactly. Getting a parse error when I run the code though:
Parse error: syntax error, unexpected T_STRING in /home/acch/artandculturecenter.org/textpattern/publish/taghandlers.php(3737) : eval()’d code on line 3
Line three being the second Header line. Is txp maybe ignoring the custom field tag inside the php? When I remove ‘name=“redirect”’, the redirect works and goes to http://artandculturecenter.org/<txp:custom_field%20/> . I did change the smart quotes to regular double quotes.
Yes, I have tried turning it off and on.
Offline
#6 2011-06-08 20:17:14
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: Simple redirect from one article to another
Header(“Location: <txp:custom_field name=“redirect” />”);
There could be also a conflict with the quotation marks.
Offline
Re: Simple redirect from one article to another
Definately the quotation marks. (my German keyboard setup, i guess).
Change all to regular double quotes, but “redirect” to ‘redirect’ in line 3.
EDIT: Quotation marks in this post still look weird, use only regular quotes, regardless of double or single.
Last edited by jayrope (2011-06-08 20:28:53)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: Simple redirect from one article to another
jayrope wrote:
EDIT: Quotation marks in this post still look weird, use only regular quotes, regardless of double or single.
The quotes come from Textile. Textile formats quotes accordingly if not told otherwise, either by escaping parsing (=="==
, notextile.) or using code blocks (bc. @"@).
Offline
Re: Simple redirect from one article to another
The TXP parser still seems to not kick in. when I change the quotes around the name parameter to single quotes, the redirect works, but I’m redirected to
http://artandculturecenter.org/<txp:custom_field%20name=‘redirect’%20/>
Is there some way I need to escape some of these quotes? I’m experimenting with every combination I can think of, but to no avail.
Yes, I have tried turning it off and on.
Offline
#10 2011-06-09 03:36:23
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,477
Re: Simple redirect from one article to another
Please write your code here in the forum beginning with …
bc. your code
or between @ your code @
Offline
Re: Simple redirect from one article to another
crossed wires happening here: one issue is how to show code in the forum so that quotes are not converted to smart quotes, the other is how to nest tags in tags. The actual problem, though, is that you can’t use txp tags inside txp:php without either calling the function directly or using parse('...')
to parse the tag:
Try using custom_field(array('name'=>'redirect'))
or parse('<txp:custom_field name="redirect" />')
to insert the custom_field value.
See also ruud’s comment in another thread.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Simple redirect from one article to another
I think that redirect pro does all the redirections automatically
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline