【发布时间】:2012-01-13 01:45:56
【问题描述】:
我想知道使用 htaccess 规则是否可以实现以下场景。 我希望将一个子域重定向到另一个 url。 我已联系服务器管理员将“test”子域添加到“example.com”域。 主域没有其他子域。
我必须在 htaccess 中加入什么规则才能实现: http://test.example.com 被重定向到http://www.something-else.com。
注意:www.something-else.com 是一个复杂的网址(长度为 200 个字符)
编辑 我的完整 htaccess 文件现在看起来像:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/redir.php [L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
htaccess 文件位于 example.com 根目录。 我没有对 test 子目录的物理访问权限,尽管我知道它存在 - ping 到该 url 会显示 example.com 的 IP
在浏览器地址栏输入 test.example.com 无效。白屏,没有重定向,什么都没有。如果那里存在某个页面,我不知道。
【问题讨论】:
-
stackoverflow.com/a/1460652/567986 但您应该删除末尾的
,P并删除 %{REQUEST_URI}。 -
我尝试了这个规则,它对我有用(当然是使用我的网站)现在你能提供更多关于
has no effect. White screen, no redirection, no nothing的信息吗,比如你能分享一个 httpfox 吗?可能是子域设置不正确之类的 -
@Book Of Zeus 当我在浏览器中输入子域地址时,它会显示一个白屏。似乎有一个页面,但没有内容。如果我尝试访问 test.example.com/index.htm,我会收到未找到的错误。网址保持不变(test.example.com)
-
日志说什么? test.example.com 文件夹中有什么(任何 .htaccess?)?
标签: .htaccess mod-rewrite subdomain redirect