Redirect

Discussion in 'HTML' started by chlori, May 1, 2004.

  1. chlori

    chlori Guest

    chlori, May 1, 2004
    #1
    1. Advertising

  2. chlori wrote:
    > Hi
    >
    > How can I redirect visitors from www.domain.com to www.domain.com/folder?
    >
    > So, if I type www.domain.com I see www.domain.com/folder
    >
    > I tried with .htaccess
    > Redirect permanent http://www.domain.com/ http://www.domain.com/folder/
    > (on one line) but it didnt't work.


    Remove the permanent, than it should be working fine.
    For more info.
    http://wsabstract.com/howto/htaccess7.shtml

    > Did I do something wrong? Or is there a way with PHP?


    You can redirect with php like:
    <?php header(Refresh: 5;url=http://www.xxx.com/"); ?>
    --
    Edwin van der Vaart
    Edwin van der Vaart, May 2, 2004
    #2
    1. Advertising

  3. Edwin van der Vaart <> writes:

    > chlori wrote:


    >> Redirect permanent http://www.domain.com/ http://www.domain.com/folder/

    ^^^^^^^^^^^^^^^^^^^^^
    >> (on one line) but it didnt't work.

    >
    > Remove the permanent,


    Why? Maybe it *is* permanent, but it would probably better to start
    with the reason for the objective, not the technical details.

    > http://wsabstract.com/howto/htaccess7.shtml


    Preferably RTFM.

    <http://httpd.apache.org/docs/mod/mod_alias.html#redirect>

    The argument for the old resource is an URL-*path* (and the status is
    optional).

    > <?php header(Refresh: 5;url=http://www.xxx.com/"); ?>


    Sigh. That's not the same. There isn't even a refresh header field in
    rfc 2616, and I don't see any particular reason to replicate the usual
    META kludge.

    The PHP equivalent of the above would be something like

    <?php

    header("HTTP/1.x 301 Moved Permanently");
    header("Location: http://www.example.com/folder/");

    ?>

    --
    | ) 111010111011 | http://bednarz.nl/
    -(
    | ) Distribute me: http://binaries.bednarz.nl/mp3/aicha
    Eric B. Bednarz, May 2, 2004
    #3
  4. "chlori" <> skrev i melding
    news:c718r9$h4sdl$-berlin.de...
    > Hi
    >
    > How can I redirect visitors from www.domain.com to
    > www.domain.com/folder?
    >
    > So, if I type www.domain.com I see www.domain.com/folder
    >
    > I tried with .htaccess
    > Redirect permanent http://www.domain.com/
    > http://www.domain.com/folder/
    > (on one line) but it didnt't work.
    >
    > Did I do something wrong?


    Yes. The file to be redirected must be a file from document root, such as /.
    Also, if you only use / as the file to be redirected, you'll get a get a
    redirect to http://www.example.com/folder/folder/folder/folder/..., which
    goes right into an infinate loop.

    This way will work, though:

    Redirect Permanent /index.html http://www.example.com/folder/


    > Or is there a way with PHP?


    <?php header("HTTP/1.x 301 Moved Permanently\nLocation:
    http://www.example.com/folder/"); ?>

    Keep in mind that your index.php file can't contain anything before the
    <?php tag, not even a space or a blank line, or you'll receive a PHP error
    ("headers already sent/received").

    --
    Kim André Akerø
    -
    (remove NOSPAM to contact me directly)
    Kim André Akerø, May 2, 2004
    #4
  5. Eric B. Bednarz wrote:

    > The PHP equivalent of the above would be something like
    >
    > <?php
    > header("HTTP/1.x 301 Moved Permanently");
    > header("Location: http://www.example.com/folder/");
    > ?>


    Though replace 'x' with your favourite positive binary integer (as long as
    it's less than 10).

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
    Toby A Inkster, May 2, 2004
    #5
  6. chlori

    Hywel Guest

    chlori wrote:

    > Hi
    >
    > How can I redirect visitors from www.domain.com to www.domain.com/folder?
    >
    > So, if I type www.domain.com I see www.domain.com/folder
    >
    > I tried with .htaccess
    > Redirect permanent http://www.domain.com/ http://www.domain.com/folder/
    > (on one line) but it didnt't work.
    >
    > Did I do something wrong? Or is there a way with PHP?


    Why are you trying to do this? Would it not be possible to simply move
    whatever's in /folder up one level to /?

    In PHP, just put this in the document index in /
    <?
    header("location:folder/");
    ?>

    --
    Hywel
    Hywel, May 2, 2004
    #6
  7. chlori

    Kris Guest

    In article <c72e8p$h9h2p$-berlin.de>,
    Hywel <> wrote:

    > In PHP, just put this in the document index in /
    > <?
    > header("location:folder/");
    > ?>


    I was recently scorned by some knowledgable people for using this
    method. They claimed that the Location header requires a full URI, not a
    relative one, according to some RFC of which I have forgotten the number.

    Can someone comment on this?

    --
    Kris
    <> (nl)
    <http://www.cinnamon.nl/>
    Kris, May 2, 2004
    #7
  8. In article <4all.nl>,
    erlands says...
    > In article <c72e8p$h9h2p$-berlin.de>,
    > Hywel <> wrote:
    >
    > > In PHP, just put this in the document index in /
    > > <?
    > > header("location:folder/");
    > > ?>

    >
    > I was recently scorned by some knowledgable people for using this
    > method. They claimed that the Location header requires a full URI, not a
    > relative one, according to some RFC of which I have forgotten the number.
    >
    > Can someone comment on this?


    This is from the PHP docs, so you're right:

    <quote>
    Note: HTTP/1.1 requires an absolute URI as argument to Location:
    including the scheme, hostname and absolute path, but some clients
    accept relative URIs. You can usually use $_SERVER['HTTP_HOST'],
    $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a
    relative one yourself:

    <?php
    header("Location: http://" . $_SERVER['HTTP_HOST']
    . dirname($_SERVER['PHP_SELF'])
    . "/" . $relative_url);
    ?>
    </quote>

    --
    Hywel I do not eat quiche
    http://kibo.org.uk/
    http://kibo.org.uk/mfaq.php
    Hywel Jenkins, May 2, 2004
    #8
  9. Kris wrote:

    >> header("location:folder/");


    > They claimed that the Location header requires a full URI, not a
    > relative one, according to some RFC of which I have forgotten the number.


    They would be right:
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30

    Some user agents (the lynx browser being an obvious example) spit warnings
    at the user when you do this. I don't know any agents which fail to
    compensate for this error, but its a pretty good bet that there are some
    out there which don't.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    David Dorward, May 2, 2004
    #9
  10. chlori

    Kris Guest

    In article <>,
    Hywel Jenkins <> wrote:

    > > > In PHP, just put this in the document index in /
    > > > <?
    > > > header("location:folder/");
    > > > ?>

    > >
    > > I was recently scorned by some knowledgable people for using this
    > > method. They claimed that the Location header requires a full URI, not a
    > > relative one, according to some RFC of which I have forgotten the number.


    > This is from the PHP docs, so you're right:
    >
    > <quote>
    > Note: HTTP/1.1 requires an absolute URI as argument to Location:
    > including the scheme, hostname and absolute path, but some clients
    > accept relative URIs. You can usually use $_SERVER['HTTP_HOST'],
    > $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a
    > relative one yourself:


    [skip PHP code for constructing absolute URI from a relative one]

    I heard there is another header that allows relative URI's for
    redirection. Looking up the URI for RFC2616 that Dorward gave [1], it
    seems to be Content-Location.

    [1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
    (The NOTE at 14.30 mentions Content-Location)

    Are there any known drawbacks for using Content-Location and a relative
    URI instead of Location and an absolute URI? I would prefer to start
    using Content-Location rather than retrofitting the effective, yet
    bothersome PHP script that was given (let alone manually entering
    absolute URI's).

    --
    Kris
    <> (nl)
    <http://www.cinnamon.nl/>
    Kris, May 2, 2004
    #10
  11. Toby A Inkster <> writes:

    > Eric B. Bednarz wrote:


    >> header("HTTP/1.x 301 Moved Permanently");


    > Though replace 'x' with your favourite positive binary integer


    -> GET /tobyink/ HTTP/1.1

    <- HTTP/1.x 200 OK


    Go ahead. :)


    --
    | ) 111010111011 | http://bednarz.nl/
    -(
    | ) Distribute me: http://binaries.bednarz.nl/mp3/aicha
    Eric B. Bednarz, May 2, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    1
    Views:
    7,073
  2. bagsmode
    Replies:
    2
    Views:
    5,468
    bagsmode
    Jul 28, 2003
  3. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,215
    Srowe1975
    Oct 15, 2008
  4. Sal
    Replies:
    1
    Views:
    376
  5. Ron Howard
    Replies:
    2
    Views:
    506
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page