Header Redirect Bug

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Philipp Lenssen

    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("Locatio n: 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!
  • laidbak

    #2
    Re: Header Redirect Bug

    >Unfortunatel y my server is shielding error messages from me

    At the top of your script add:

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

    --
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~
    Wil Moore III, MCP Site : www.quicksitedesign.com?em
    Application Developer Site : www.digitallysmooth.com?em
    ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~


    Comment

    • Pedro Graca

      #3
      Re: Header Redirect Bug

      Philipp Lenssen wrote:[color=blue]
      > ------- Sample -------
      > <?
      > header("HTTP/1.1 301 Moved permanently");
      > header("Locatio n: 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.[/color]

      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 =--

      Comment

      • Andy Hassall

        #4
        Re: Header Redirect Bug

        On 20 Jan 2004 20:58:58 GMT, "Philipp Lenssen" <info@outer-court.com> wrote:
        [color=blue]
        >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("Locati on: 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.[/color]

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



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

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

        --
        Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
        <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

        Comment

        • Philipp Lenssen

          #5
          Re: Header Redirect Bug

          Pedro Graca wrote:
          [color=blue]
          > header('HTTP/1.1 301 Moved permanently');
          > header('HTTP/1.1 302 http://www.example.com/'); // also try 307[/color]

          That doesn't work...

          Comment

          • Philipp Lenssen

            #6
            Re: Header Redirect Bug

            laidbak wrote:
            [color=blue][color=green]
            > > Unfortunately my server is shielding error messages from me[/color]
            >
            > At the top of your script add:
            >
            > <?php
            > error_reporting (E_ALL);
            > ini_set('displa y_errors', true);
            > ?>[/color]

            I added it but still cannot see the error message other than the
            default "Error occurred"...

            Comment

            • Pedro Graca

              #7
              Re: Header Redirect Bug

              Philipp Lenssen wrote:[color=blue]
              > ------- Sample -------
              > <?
              > header("HTTP/1.1 301 Moved permanently");
              > header("Locatio n: http://www.example.com ");
              > ?>
              > ----------------------[/color]

              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 =--

              Comment

              • kicken

                #8
                Re: Header Redirect Bug

                Philipp Lenssen wrote:[color=blue]
                > 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("Locatio n: 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![/color]

                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.

                Comment

                • Philipp Lenssen

                  #9
                  Re: Header Redirect Bug

                  Andy Hassall wrote:
                  [color=blue]
                  > On 20 Jan 2004 20:58:58 GMT, "Philipp Lenssen" <info@outer-court.com>
                  > wrote:
                  >[/color]
                  [color=blue][color=green]
                  > > ------- Sample -------
                  > > <?
                  > > header("HTTP/1.1 301 Moved permanently");
                  > > header("Locatio n: http://www.example.com ");
                  > > ?>
                  > > ----------------------[/color][/color]
                  [color=blue]
                  >
                  > You haven't said what problem you're actually having, other than it
                  > 'breaks your script'.
                  >[/color]

                  That's part of my problem -- my server hides the error message, and I
                  can't turn it on.
                  [color=blue]
                  > http://uk.php.net/header
                  >
                  > What you're doing appears correct from the manual. There's also the
                  > alternative of:[/color]

                  Yes, I guess my server is somehow misconfigured.
                  [color=blue]
                  >
                  > header("Locatio n: http://www.example.com ", false, 301);
                  >[/color]

                  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".

                  Comment

                  • Philipp Lenssen

                    #10
                    Re: Header Redirect Bug

                    Pedro Graca wrote:
                    [color=blue]
                    > Philipp Lenssen wrote:[color=green]
                    > > ------- Sample -------
                    > > <?
                    > > header("HTTP/1.1 301 Moved permanently");
                    > > header("Locatio n: http://www.example.com ");
                    > > ?>
                    > > ----------------------[/color]
                    >
                    > Does the redirection work with your sample script being the whole
                    > script?[/color]

                    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).

                    Comment

                    • Philipp Lenssen

                      #11
                      Re: Header Redirect Bug

                      kicken wrote:
                      [color=blue]
                      >
                      > 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.[/color]

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

                      Comment

                      • Pedro Graca

                        #12
                        Re: Header Redirect Bug

                        Philipp Lenssen wrote:[color=blue]
                        > Pedro Graca wrote:
                        >[color=green]
                        >> Philipp Lenssen wrote:[color=darkred]
                        >> > ------- Sample -------
                        >> > <?
                        >> > header("HTTP/1.1 301 Moved permanently");
                        >> > header("Locatio n: http://www.example.com ");
                        >> > ?>
                        >> > ----------------------[/color]
                        >>
                        >> Does the redirection work with your sample script being the whole
                        >> script?[/color]
                        >
                        > 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).[/color]

                        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 =--

                        Comment

                        • Philipp Lenssen

                          #13
                          Re: Header Redirect Bug

                          Pedro Graca wrote:
                          [color=blue]
                          > Philipp Lenssen wrote:[color=green]
                          > > Pedro Graca wrote:
                          > >[color=darkred]
                          > >> Philipp Lenssen wrote:
                          > >> > ------- Sample -------
                          > >> > <?
                          > >> > header("HTTP/1.1 301 Moved permanently");
                          > >> > header("Locatio n: http://www.example.com ");
                          > >> > ?>
                          > >> > ----------------------
                          > >>
                          > >> Does the redirection work with your sample script being the whole
                          > >> script?[/color]
                          > >
                          > > 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).[/color]
                          >
                          > I guess you mean it does not work.
                          >[/color]

                          Yes, sorry got it mixed up. It does _not_ work.
                          [color=blue]
                          > ... have you tried switching the header()s order?[/color]

                          Good idea. Will try.

                          Nope. Same 500 error.

                          Comment

                          • kicken

                            #14
                            Re: Header Redirect Bug

                            Philipp Lenssen wrote:[color=blue]
                            > kicken wrote:
                            >
                            >[color=green]
                            >>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.[/color]
                            >
                            >
                            > I can use the header function to redirect, however I cannot send the
                            > 301 permanent move.[/color]

                            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.

                            Comment

                            • Chung Leong

                              #15
                              Re: Header Redirect Bug

                              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_fi rst_header");
                              header("Locatio n: http://www.example.com ");
                              touch("after_se cond_header");

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

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

                              Uzytkownik "Philipp Lenssen" <info@outer-court.com> napisal w wiadomosci
                              news:buli47$ig1 gn$3@ID-203055.news.uni-berlin.de...[color=blue]
                              > Pedro Graca wrote:
                              >[color=green]
                              > > Philipp Lenssen wrote:[color=darkred]
                              > > > Pedro Graca wrote:
                              > > >
                              > > >> Philipp Lenssen wrote:
                              > > >> > ------- Sample -------
                              > > >> > <?
                              > > >> > header("HTTP/1.1 301 Moved permanently");
                              > > >> > header("Locatio n: 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).[/color]
                              > >
                              > > I guess you mean it does not work.
                              > >[/color]
                              >
                              > Yes, sorry got it mixed up. It does _not_ work.
                              >[color=green]
                              > > ... have you tried switching the header()s order?[/color]
                              >
                              > Good idea. Will try.
                              >
                              > Nope. Same 500 error.[/color]


                              Comment

                              Working...