我有一个网站(比如名字www.manoj.com
),我在子域名上创建了一个论坛
forum.manoj.com
现在,我想将manoj.com/forum/{anything else}
之后的所有链接重定向到forum.manoj.com/{anything else}
我该怎么做。
由于
答案 0 :(得分:3)
如果您想将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
中定义。有关详情,请参阅this