[英]How to set a URL rewrite for sub-domain links like these?
我有一個網站(名稱為www.manoj.com
),並且在子域上創建了一個論壇
forum.manoj.com
現在,我想將manoj.com/forum/{anything else}
之后的所有鏈接重定向到forum.manoj.com/{anything else}
我該怎么做。
謝謝
如果要將example.com/forum
重定向到forum.example.com
,請在[document_root]/forum/.htaccess
編寫:
RewriteEngine On
RewriteBase /forum
RewriteCond %{REMOTE_HOST} !=forum.example.com
RewriteRule (.*) http://forum.example.com/$1 [R=301,NE,L]
R=301
標志用於指示它是“永久”重定向,Apache將發送標頭HTTP/1.1 301 Moved Permanently
。
如果您確實無法在其中添加.htaccess
文件,請在[document_root]/.htaccess
寫入:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !=forum.example.com
RewriteRule forum/(.*) http://forum.example.com/$1 [R=301,NE,L]
但這還不夠。 您需要先為forum.example.com
設置DNS記錄,然后在服務器上設置虛擬主機(如果使用Apache),然后才能運行。 通常,虛擬主機在httpd.conf
中定義。 欲了解更多看到這
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.