473,232 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

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 4311
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?>...
7
by: Monty | last post by:
Something odd is happening. Scripts on several sites that collect form data, save it to a DB, then redirect the user to another page are slowing to a crawl during the redirect using the header()...
3
by: maya | last post by:
yes I know, this has been asked many times, but I don't quite the answers: usu. answers are to put the redirect code -- in my case $URL =...
12
by: Jerim79 | last post by:
I have created a verification script to verify information and redirect the customer to the appropriate error page. For example: if ($FName=""){ header('Location:/verify_fname.htm'); } else{...
5
by: One | last post by:
Hi guys - I have a problem after a client clicks a Confirm button on a form - the form processes the data, inserts into a database, and then redirects using header Location. I have tested this...
19
by: Justin | last post by:
Harlow... i need some help on these... im actually trying to do a page using php... the function is to receive certain parameters from a 3rd party provider... and i need to redirect my page to...
4
by: Call Me Tom | last post by:
I was looking at an application with the following code snippet: ob_start(); session_name('foo'); session_start(); if (!$_SESSION) { header("Location: http://" . $_SERVER . dirname($_SERVER)...
0
by: JRough | last post by:
I have the following code at the end of a page that lists some query results. It starts in a form that asks the user for input, one of two template pages. One template is a form for user input if...
2
by: JRough | last post by:
I have this code that switches templates depending on if the user fills in a form with a request. The request asks for the $mark & $number. If that request gets input then it displays a list...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.