Re: Header Redirect
| From: | Stut | Date: | Tue, 27 May 2008 16:57:36 +0000 |
| Subject: | Re: Header Redirect | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274743@lists.php.net to get a copy of this message | ||
On 27 May 2008, at 17:45, Yui Hiroaki wrote:
I try it following your adivice; Code*************************************** <?php $uuu=$_SERVER["QUERY_STRING"]; if ($_SERVER['REQUEST_URI'] == '/index.php'."?"."$uuu") { header("HTTP/1.1 301 Moved Permanently"); header("Location: http://example.com/"); exit(); } ?> But I still need toconfigure below; http://example/index.php?123233 and http://example/index.php/?123233 Can you help me?<?php if (strlen($_SERVER['QUERY_STRING']) > 0) {
// The third parameter of the header function can be
// used to set the response code.
header('Location: http://example.com/', true, 301);
// You really should output something here so that in
// the unlikely event the client doesn't auto-follow
// the redirect the user is not left in the lurch.
echo 'Moved <a href="http://example.com/">here</a>';
exit;} ?> Rocket science it ain't! But I repeat... this seems to be a completely pointless redirect. The user is already requesting the index page, so why redirect them back to the index page? -Stut -- http://stut.net/ > 2008/5/28 Stut <stuttle@gmail.com>: >> On 27 May 2008, at 17:06, Yui Hiroaki wrote: >>> >>> I would like to have some question. >>> >>> For example, >>> I am in http://example.com/?12324242 >>> >>> I would like to REDIRECT from http://example.com/?1312323232 >>> to http://example.com/ >>> >>> I can REDIRECT from http://example.com/index.php to http://example.com >>> >>> >>> Please do tell me how I can redirect! >>> >>> >>> This is the sample what I test below! >>> >>> <?php >>> if ($_SERVER['REQUEST_URI'] == '/index.php') { >>> header("HTTP/1.1 301 Moved Permanently"); >>> header("Location: http:///example.com/"); >>> exit(); >>> } >>> ?> >> >> 1) Why? Redirects should be avoided where possible for performance >> reasons. >> >> 2) If you have to then the code you have will work but you need to >> check >> $_SERVER['QUERY_STRING'] rather than REQUEST_URI. >> >> -Stut >> >> -- >> http://stut.net/ >>