Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2008-04-12 12:47:10

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: To link "write title" directly to offsite URL..

What I am wondering is if the header (re-) location trick really works inside an article body after several output was sent to the client. PHP docu (search) tells me that even a space before the call provokes an error.

<html>
<?php
/* error provocation because of earlier output */
header('Location: http://www.example.com/');
?>

Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#14 2008-04-12 13:36:06

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: To link "write title" directly to offsite URL..

Textpattern uses output buffering, so it sends browser output at the very end of the whole script. Thus, header() can be used even if some output occured previously, as stated in the PHP manual notes:

Note: As of PHP 4, you can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.

Offline

#15 2008-04-12 16:41:35

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: To link "write title" directly to offsite URL..

wet: Still wondering then why your exactly copied header location code doesn’t work inside my articles.


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#16 2008-04-12 16:45:02

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: To link "write title" directly to offsite URL..

A trace by HTTP Live Headers might help to see what get through to the client end.

Offline

#17 2008-04-13 12:42:33

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: To link "write title" directly to offsite URL..

Hmpff…!?

  • Turned asy_jpcache off

Used code (+ 301. , + exit):

<txp:if_individual_article>
 <notextile>
  <txp:php>
   header('Location: http://sankt-georg.info/tag/bunte-lange-reihe',TRUE,301);
   exit;
  </txp:php>
 </notextile>
</txp:if_individual_article>

Even forcing the permanent redirect with the 301 returns just a 200 and the message “OK The document has moved here” but no redirect.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>200 OK</TITLE>
</HEAD><BODY>
<H1>OK</H1>
The document has moved <A HREF="http://sankt-georg.info/tag/bunte-lange-reihe">here</A>.<P>
</BODY></HTML>

The header sent back laconically says:

HTTP/1.x 200 OK
Date: Sun, 13 Apr 2008 12:29:26 GMT
Server: Apache/1.3.34 Ben-SSL/1.55
Cache-Control: no-cache
X-Powered-By: PHP/4.4.8
Location: http://sankt-georg.info/tag/bunte-lange-reihe
Keep-Alive: timeout=2, max=199
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

Does it look like an ISP issue?
I have to check my dashboard at ’1&1 Germany’. Maybe they do redirects only from the slow admin console (arghh).


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#18 2008-04-14 05:26:37

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: To link "write title" directly to offsite URL..

It could either be a server issue, or some misbehaving redirector plugin. As far as I can see, it is off-topic in this thread.

Offline

#19 2008-04-14 10:28:51

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: To link "write title" directly to offsite URL..

it is off-topic in this thread.

Yep. Confirm. Will check myself what is happening. Thanks for your patience.


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#20 2008-04-14 11:30:54

SebastianS
Member
From: Australia
Registered: 2007-10-05
Posts: 46

Re: To link "write title" directly to offsite URL..

Jukka,
“Sebastian, not to the body itself, instead use the specific form, it’s much easier. The custom field launches the code, so no need to use the actual body.”

Just to confirm what I did:-

Using either Roberts code or your code, both codes work, and placing either into “Presentation/Forms”, calling the form article_url, and saving it as a “Type/Article.

I then went Content/Write and placed the url of the header I wanted to use in the article_url custom field I had made in Admin/Preferences/Advanced.

To make header perform the way I wanted I put a <txp:output_form form=“article_url” /> form in the article body, without using this output form, the header link does not link to the chosen URL but links back within the “local” website.

Thanks again for your replies.

Offline

#21 2008-04-14 11:42:22

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

Re: To link "write title" directly to offsite URL..

SebastianS wrote:

To make header perform the way I wanted I put a <txp:output_form form=“article_url” /> form in the article body, without using this output form, the header link does not link to the chosen URL but links back within the “local” website.

You can put the <txp:output_form form="article_url" /> to your form that you use for those specific articles, in example to your form called default. Then it will automatically redirect when you have filled the custom_field and you don’t need to place the extra, and somwhat useless code to the body. You can also place the code directly to the specific article form, in example default, without the output_form. That way it also reduces the amount of queries.

Last edited by Gocom (2008-04-14 11:47:13)

Offline

#22 2008-05-28 16:04:03

sthmtc
Member
From: CGN, GER
Registered: 2005-01-17
Posts: 586
Website

Re: To link "write title" directly to offsite URL..

wet wrote:

It could either be a server issue, or some misbehaving redirector plugin. As far as I can see, it is off-topic in this thread.

i hate to revive this thread and becoming off-topic again, but i’m having the exact same issues as markus and am pretty much clueless on how this can be solved. i’ve inserted wet’s aforementioned codesnippet in an articles body and instead of being redirected, i’m getting a “200 OK” from the server and the usual “The document has moved here” message. where should i start fixing this?

Offline

#23 2008-05-28 17:24:43

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: To link "write title" directly to offsite URL..

As PHP versions below below 4.3.0 won’t transmit the HTTP status set via the header() function, it might help to explicitly specify the HTTP response status with a little more insistence.

Try this:

<txp:if_individual_article>
 <notextile>
  <txp:php>
   txp_status_header('301 Moved Permanently');
   header('Location: http://example.com/');
   exit;
  </txp:php>
 </notextile>
</txp:if_individual_article>

Offline

#24 2008-05-28 17:34:01

sthmtc
Member
From: CGN, GER
Registered: 2005-01-17
Posts: 586
Website

Re: To link "write title" directly to offsite URL..

wet. you are my hero. thank you so much, works like a charm.

Offline

Board footer

Powered by FluxBB