shantanuo
shantanuo

Reputation: 32316

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

Upvotes: 0

Views: 132

Answers (3)

Carlos Gutiérrez
Carlos Gutiérrez

Reputation: 14282

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] 

Upvotes: 1

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36617

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

Upvotes: 2

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

Why not try javascript which is easiest

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

Happy coding

Upvotes: 0

Related Questions