2016-05-12 99 views
2

試圖在StackOverflow中搜索很多,但沒有解決我的問題。重定向而不更改顯示的URL

我在服務器中獲得了一個域(我們稱之爲mydomain.com)和一個名爲mydomain.com/subdomain的子域。我將DNS配置爲重定向,所以當我寫www.subdomain.com時,它會將我帶到www.mydomain.com/subdomain。

有沒有一種方法(通過DNS,CNAME,.htaccess,別的?)來執行我的重定向,但讓我的瀏覽器仍然在URL欄中顯示www.subdomain.com?

對不起,我的英文不好

+0

你可以使用[ProxyPass](https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass),al你可以用[mod_rewrite P標誌](https://httpd.apache.org/docs/current/rewrite/flags.html#flag_p)來做,但是由於性能方面的原因,建議使用proxypass。 –

+0

您的問題存在錯誤。在諸如subdomain.example.com/subdirectory/的URL中,子域是「子域」,子目錄是「子目錄」(有時也稱爲文件夾)。如果你還不清楚看到這個https://www.mattcutts.com/blog/seo-glossary-url-definitions/ 從https://www.mattcutts.com/blog/subdomains-and-subdirectories/ – javidazac

回答

1

將下面的代碼在根.htaccess文件:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{REQUEST_URI} !^/subdomain/ 
RewriteRule ^(.*)$ /subdomain/$1 [L,NE] 

更新:按javidazac評論,我應該解釋一下,要提問,他表示子目錄不子域,但我會認爲你有子目錄稱爲子域

+0

謝謝您的回答。但它沒有工作。它似乎實際上什麼都沒做!我真的不知道我在哪裏弄錯... –

+0

你把這個代碼放在哪裏?在哪個目錄中? –