Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Redirect

Reply
Thread Tools

Redirect

 
 
chlori
Guest
Posts: n/a
 
      05-01-2004
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?

Thanks
chlori
 
Reply With Quote
 
 
 
 
Edwin van der Vaart
Guest
Posts: n/a
 
      05-01-2004
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
 
Reply With Quote
 
 
 
 
Eric B. Bednarz
Guest
Posts: n/a
 
      05-02-2004
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
 
Reply With Quote
 
Kim André Akerĝ
Guest
Posts: n/a
 
      05-02-2004
"chlori" <> skrev i melding
news:c718r9$h4sdl$...
> 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)


 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      05-02-2004
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

 
Reply With Quote
 
Hywel
Guest
Posts: n/a
 
      05-02-2004
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
 
Reply With Quote
 
Kris
Guest
Posts: n/a
 
      05-02-2004
In article <c72e8p$h9h2p$>,
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/>
 
Reply With Quote
 
Hywel Jenkins
Guest
Posts: n/a
 
      05-02-2004
In article <kristiaan->,
erlands says...
> In article <c72e8p$h9h2p$>,
> 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
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      05-02-2004
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/....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/>
 
Reply With Quote
 
Kris
Guest
Posts: n/a
 
      05-02-2004
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/....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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Response.redirect does not redirect from .aspx page =?Utf-8?B?VHJveQ==?= ASP .Net 3 10-15-2008 09:07 PM
Fix Google Tracking/redirect URLs, Proxo filter Splibbilla Firefox 2 07-23-2005 09:13 AM
Redirect to secure FTP site via response.redirect Ron Howard ASP General 2 08-11-2004 07:40 PM
Redirect LPT1 to COM4 for Bluetooth printing Bitman Wireless Networking 3 07-22-2004 06:19 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57