2010-01-11 57 views

回答

2

在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; 
    } 
    ?> 

不要忘記exit;

好運,
亨裏克

+0

如果我使用的回聲 「$網址」 那麼什麼是預期的輸出?我沒有得到任何東西! – shantanuo 2010-01-11 08:14:33

+0

預期的輸出應該是您網站的完整網址 – 2010-01-11 08:49:42

0

爲什麼不嘗試的JavaScript這是最簡單的

<腳本> window.location.href = 「http://public.mysite.com」; < /腳本>

快樂編碼

+0

嗯,這裏的問題在於它是相同的索引頁面。 – 2010-01-11 06:24:23

1

可與Apache的.htaccess來完成,像這樣:

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