开发者

redirect to the current page

What is the best way to redirect the user coming from one URL to another?

I have 2 locations.

http:mysite.com http://public.mysite.com

I want t开发者_如何学运维he users who type http://mysite.com to be redirected to http://public.mysite.com It would have been easy if there were 2 different index.php files, but the index.php file is the same in both the cases.


On mysite.com:

    <?php
    $url = “http” . ((!empty($_SERVER['HTTPS'])) ? “s” : “”) . “://”.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if($url != "http://public.mysite.com") {
       header("Location: http://public.mysite.com");
       exit;
    }
    ?>

Don't forget the exit;!

Good Luck,
Henrik


Can be done with apache's .htaccess, something like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^\.mysite\.com$
RewriteRule (.*) http://public.mysite.com/$1 [R=301,L] 


Why not try javascript which is easiest

<script> window.location.href = "http://public.mysite.com"; </script>

Happy coding

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜