问题描述
我有一个网站(比如通过名称 www.manoj.com
)和我创建的子域名论坛
I have a site ( say by name www.manoj.com
) and I have created a forum on sub-domain
forum.manoj.com
现在,我要重定向所有下面的链接 manoj.com/forum/ {别的}
到 forum.manoj.com/ {别的}
Now, I want to redirect all the links following manoj.com/forum/{anything else}
to forum.manoj.com/{anything else}
我怎样才能做到这一点。
How can I do it.
感谢
推荐答案
如果要重定向 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永久移动
。
The R=301
flag is to indicate it is a "permanent" redirect, Apache will send the header HTTP/1.1 301 Moved Permanently
.
如果你真的不能添加的.htaccess
文件存在,在 [DOCUMENT_ROOT] / htaccess的
写:
If you really cannot add a .htaccess
file there, in [document_root]/.htaccess
write:
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
定义。欲了解更多请参见这
But this is not enough. You need to set the DNS record for forum.example.com
and set up virtual host (if you use Apache) on the server before it will work. Typically virtual hosts are defined in httpd.conf
. For more see this
这篇关于如何设置一个URL重写像这些子域名的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!