473,378 Members | 1,420 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,378 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 4318
>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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.