Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-08 15:16:16

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#2 2011-06-08 16:36:57

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

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

#3 2011-06-08 17:18:55

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#4 2011-06-08 17:29:40

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

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

#5 2011-06-08 19:26:20

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#7 2011-06-08 20:26:06

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 689
Website Mastodon

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

#8 2011-06-08 21:14:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

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

#9 2011-06-09 03:21:47

alesh
Member
From: Miami, FL
Registered: 2005-04-13
Posts: 228
Website

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

#11 2011-06-09 07:19:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

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

Online

#12 2011-06-09 07:42:30

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,258
Website GitHub Mastodon Twitter

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

Board footer

Powered by FluxBB