469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Header Redirect Bug

I have a problem doing a permanent redirect. It works only if I
directly send the new location header (third line in sample below) but
never in combination with sending a "301 Moved permanently" first
(second line below). Unfortunately my server is shielding error
messages from me (and I don't have access to the PHP.INI).

------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------

(Note: there is no space anywhere or anything else before I send the
header. Also: I cannot send the "Moved permanently" on its own either.
It always breaks my script, but I don't know why.)

What can I do? If I redirect without 301 I'm afraid Google won't change
it's index of my pages.

Any help greatly appreciated!
Jul 17 '05 #1
18 4169
>Unfortunately my server is shielding error messages from me

At the top of your script add:

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Wil Moore III, MCP Site : www.quicksitedesign.com?em
Application Developer Site : www.digitallysmooth.com?em
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~
Jul 17 '05 #2
Philipp Lenssen wrote:
------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------

What can I do? If I redirect without 301 I'm afraid Google won't change
it's index of my pages.


Maybe?

<?php
header('HTTP/1.1 301 Moved permanently');
header('HTTP/1.1 302 http://www.example.com/'); // also try 307
?>

HTTP RFC: http://www.faqs.org/rfcs/rfc2616.html
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
On 20 Jan 2004 20:58:58 GMT, "Philipp Lenssen" <in**@outer-court.com> wrote:
I have a problem doing a permanent redirect. It works only if I
directly send the new location header (third line in sample below) but
never in combination with sending a "301 Moved permanently" first
(second line below). Unfortunately my server is shielding error
messages from me (and I don't have access to the PHP.INI).

------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------

(Note: there is no space anywhere or anything else before I send the
header. Also: I cannot send the "Moved permanently" on its own either.
It always breaks my script, but I don't know why.)

What can I do? If I redirect without 301 I'm afraid Google won't change
it's index of my pages.


You haven't said what problem you're actually having, other than it 'breaks
your script'.

http://uk.php.net/header

What you're doing appears correct from the manual. There's also the
alternative of:

header("Location: http://www.example.com", false, 301);

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Jul 17 '05 #4
Pedro Graca wrote:
header('HTTP/1.1 301 Moved permanently');
header('HTTP/1.1 302 http://www.example.com/'); // also try 307


That doesn't work...
Jul 17 '05 #5
laidbak wrote:
Unfortunately my server is shielding error messages from me


At the top of your script add:

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
?>


I added it but still cannot see the error message other than the
default "Error occurred"...
Jul 17 '05 #6
Philipp Lenssen wrote:
------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------


Does the redirection work with your sample script being the _whole_
script?
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #7
Philipp Lenssen wrote:
I have a problem doing a permanent redirect. It works only if I
directly send the new location header (third line in sample below) but
never in combination with sending a "301 Moved permanently" first
(second line below). Unfortunately my server is shielding error
messages from me (and I don't have access to the PHP.INI).

------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------

(Note: there is no space anywhere or anything else before I send the
header. Also: I cannot send the "Moved permanently" on its own either.
It always breaks my script, but I don't know why.)

What can I do? If I redirect without 301 I'm afraid Google won't change
it's index of my pages.

Any help greatly appreciated!


Are you running php as an apache module, or as some type of CGI setup
where the web-server executes php.exe? If it's the latter, then you
can't change the HTTP response header as far ask I know. Only with the
apache module can that be accomplished.
Jul 17 '05 #8
Andy Hassall wrote:
On 20 Jan 2004 20:58:58 GMT, "Philipp Lenssen" <in**@outer-court.com>
wrote:
------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------


You haven't said what problem you're actually having, other than it
'breaks your script'.

That's part of my problem -- my server hides the error message, and I
can't turn it on.
http://uk.php.net/header

What you're doing appears correct from the manual. There's also the
alternative of:
Yes, I guess my server is somehow misconfigured.

header("Location: http://www.example.com", false, 301);


Thanks. That at least didn't cause an error. However the page now
appeared white, and no redirect could be seen in the browser. Also if I
set the second parameter to "true".
Jul 17 '05 #9
Pedro Graca wrote:
Philipp Lenssen wrote:
------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------


Does the redirection work with your sample script being the whole
script?


Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).
Jul 17 '05 #10
kicken wrote:

Are you running php as an apache module, or as some type of CGI setup
where the web-server executes php.exe? If it's the latter, then you
can't change the HTTP response header as far ask I know. Only with
the apache module can that be accomplished.


I can use the header function to redirect, however I cannot send the
301 permanent move.
Jul 17 '05 #11
Philipp Lenssen wrote:
Pedro Graca wrote:
Philipp Lenssen wrote:
> ------- Sample -------
> <?
> header("HTTP/1.1 301 Moved permanently");
> header("Location: http://www.example.com");
> ?>
> ----------------------


Does the redirection work with your sample script being the whole
script?


Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).


I guess you mean it does *not* work.

.... have you tried switching the header()s order?
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #12
Pedro Graca wrote:
Philipp Lenssen wrote:
Pedro Graca wrote:
Philipp Lenssen wrote:
> ------- Sample -------
> <?
> header("HTTP/1.1 301 Moved permanently");
> header("Location: http://www.example.com");
> ?>
> ----------------------

Does the redirection work with your sample script being the whole
script?
Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).


I guess you mean it does not work.


Yes, sorry got it mixed up. It does _not_ work.
... have you tried switching the header()s order?


Good idea. Will try.

Nope. Same 500 error.
Jul 17 '05 #13
Philipp Lenssen wrote:
kicken wrote:

Are you running php as an apache module, or as some type of CGI setup
where the web-server executes php.exe? If it's the latter, then you
can't change the HTTP response header as far ask I know. Only with
the apache module can that be accomplished.

I can use the header function to redirect, however I cannot send the
301 permanent move.


Yea, what I was saying, is that in a CGI setup, doing a header to change
the http response will not work. Other headers will though.

header('HTTP ...'); type headers won't work unless you have the apache
module. It's noted in the manual.
Jul 17 '05 #14
Is the script dying after the first call to header()? Run this and see which
files get created:

header("HTTP/1.1 301 Moved permanently");
touch("after_first_header");
header("Location: http://www.example.com");
touch("after_second_header");

// perhaps track_errors is on?
fwrite(fopen("php_errormsg", "w"), $php_errormsg);

Also try changing the header to "HTTP/1.0".

Uzytkownik "Philipp Lenssen" <in**@outer-court.com> napisal w wiadomosci
news:bu************@ID-203055.news.uni-berlin.de...
Pedro Graca wrote:
Philipp Lenssen wrote:
Pedro Graca wrote:

> Philipp Lenssen wrote:
> > ------- Sample -------
> > <?
> > header("HTTP/1.1 301 Moved permanently");
> > header("Location: http://www.example.com");
> > ?>
> > ----------------------
>
> Does the redirection work with your sample script being the whole
> script?

Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).


I guess you mean it does not work.


Yes, sorry got it mixed up. It does _not_ work.
... have you tried switching the header()s order?


Good idea. Will try.

Nope. Same 500 error.

Jul 17 '05 #15
Chung Leong wrote:
Is the script dying after the first call to header()? Run this and
see which files get created:

header("HTTP/1.1 301 Moved permanently");
touch("after_first_header");
header("Location: http://www.example.com");
touch("after_second_header");

// perhaps track_errors is on?
fwrite(fopen("php_errormsg", "w"), $php_errormsg);

Also try changing the header to "HTTP/1.0".


Thanks for trying to help. The script idea doesn't work on my
misconfigured served which I don't have complete control over. The
"php_errormsg" was created, but empty. I'm now trying to figure out how
to solve this problem right within the htaccess file, and this is my
current try:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)-([0-9]*).html show.php?title=$1&part=$2

And then someone suggested this but it doesn't quite work for me...

RewriteCond %{QUERY_STRING} ^title=([a-z]+)&part=([0-9]+)
RewriteRule ^book.php$ %1-%2? [redirect=permanent]
Jul 17 '05 #16
Regarding this well-known quote, often attributed to Philipp Lenssen's
famous "21 Jan 2004 09:04:55 GMT" speech:
Pedro Graca wrote:
Philipp Lenssen wrote:
------- Sample -------
<?
header("HTTP/1.1 301 Moved permanently");
header("Location: http://www.example.com");
?>
----------------------


Does the redirection work with your sample script being the whole
script?


Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).


Any chance you can get to your error log files? Also, have you tried
threatening bodily harm to your provider's employees unless they start
showing you your rightly-deserved error messages...

Who knows, it might work... might get you thrown in jail, tho'.

--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com
Jul 17 '05 #17
"Philipp Lenssen" <in**@outer-court.com> wrote in message news:<bu************@ID-203055.news.uni-berlin.de>...
Pedro Graca wrote:
Philipp Lenssen wrote:
Pedro Graca wrote:

> Philipp Lenssen wrote:
> > ------- Sample -------
> > <?
> > header("HTTP/1.1 301 Moved permanently");
> > header("Location: http://www.example.com");
> > ?>
> > ----------------------
>
> Does the redirection work with your sample script being the whole
> script?

Yes. No spaces before or after. Complete sample above pasted into
text-editor, uploaded via FTP, and run via HTTP -- Error 500 (exact
error shielded by server).


I guess you mean it does not work.


Yes, sorry got it mixed up. It does _not_ work.
... have you tried switching the header()s order?


Good idea. Will try.

Nope. Same 500 error.


Adjust your browser settings to see no-friendly HTTP message or
just use some HTTP sniffers to see the all the responses. I guess, the
script dies somewhere. May be you could post the URL of the page?

--
"We live to die; We die to live"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #18
R. Rajesh Jeba Anbiah wrote:
Adjust your browser settings to see no-friendly HTTP message or
just use some HTTP sniffers to see the all the responses. I guess, the
script dies somewhere. May be you could post the URL of the page?


It's the error message HTML of my host... not the browser-one... but
thanks to all I officially give up on solving this with PHP and instead
try to solve it via htaccess. In fact I offer $20 at Google Answers for
a solution:
<http://answers.google.com/answers/threadview?id=299291>
Jul 17 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bob Garbados | last post: by
12 posts views Thread by Jerim79 | last post: by
5 posts views Thread by One | last post: by
19 posts views Thread by Justin | last post: by
4 posts views Thread by Call Me Tom | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.