繁体   English   中英

如何为此类子域链接设置URL重写?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM