我使用 hostmonster 帐户托管多个网站。每个站点都位于我的 public_html 文件夹的子目录中,以便在管理站点时让我保持清醒。例如,我的主域位于 public_html/joshorndorff.com
我已经在我的 public_html 文件夹中设置了我的 .htaccess 文件,以按照https://my.hostmonster.com/cgi/help/347的建议将流量重定向到适当的子目录
# .htaccess main domain to subdirectory redirect
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?joshorndorff.com$
RewriteCond %{REQUEST_URI} !^/joshorndorff.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /joshorndorff.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?joshorndorff.com$
RewriteRule ^(/)?$ joshorndorff.com/index.php [L]
然后在我的子目录中,我使用drupal 默认的.htaccess 作为取消注释重定向到www 的行。子域。子目录中的相关行是:
RewriteCond %{HTTP_HOST} ^joshorndorff\.com$ [NC]
RewriteRule ^(.*)$ http://www.joshorndorff.com/$1 [L,R=301]
这一切都很好,但我仍然有两个问题。
当我键入 www.joshorndorff.com/joshorndorff.com/index.php 时,不会发生重写,并且域名和子目录(与域名相同的名称)都显示在地址栏中
当我在地址栏中输入我的静态 IP 地址 (67.20.112.212) 时,我没有被重定向到我的网站,而是看到我放入 public_html 中的 index.html 用于测试目的/
我在http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/上阅读了关于 mod_rewrite 的优秀教程,但仍然无法解决这两个问题中的任何一个。我会喜欢任何建议或工作代码,但更想了解为什么 RewriteRule ^joshorndorff.com/ / [NC]
不符合我的预期。
非常感谢!——乔什·奥恩多夫