绑定Bluehost主域名到任意目录
在bluehost的虚拟主机中,默认是将public_html(www目录是public_html目录的链接文件)目录作为主域名的根目录的;而子域名或附加域名的根目录是在public_html目录的同名目录中。这样就造成了主域名的程序文件和子域名根目录混淆在一起,看上去很乱。幸好我们有.htaccess文件(需是apache服务器),利用它的重写功能将主域名的根目录”重定向”到一个子目录中,即主域名的根目录与其它域名的根目录都处于public_html目录中,这样看上去就干净多了。
具体的写法如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # .htaccess main domain to subfolder redirect # Copy and paste the following code into the .htaccess file # in the public_html folder of your hosting account # make the changes to the file according to the instructions. # 打开apache重写引擎 RewriteEngine on # 设置重写条件1 RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ # 设置重写条件2 RewriteCond %{REQUEST_URI} !^/subfolder/ # 设置重定条件3(非文件或目录请求) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # 满足上述三个条件则执行重写规则1 RewriteRule ^(.*)$ /subfolder/$1 # Change yourdomain.com to be your main domain again. # Change 'subfolder' to be the folder you will use for your main domain # followed by / then the main file for your site, index.php, index.html, etc. # 重写规则2 RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ RewriteRule ^(/)?$ subfolder/index.php [L] |
说明:将yourmaindomain.com替换成你的主域名;subfolder是你更改后的主域名的根目录名;最后将该.htaccess文件放到public_html目录即可。现在开始清理你的public_html目录吧,还你一个干干净净的主目录。[参考]
英文版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # Bluehost.com # .htaccess main domain to subfolder redirect # Copy and paste the following code into the .htaccess file # in the public_html folder of your hosting account # make the changes to the file according to the instructions. # Do not change this line. RewriteEngine on # Change yourdomain.com to be your main domain. RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ # Change ’subfolder’ to be the folder you will use for your main domain. RewriteCond %{REQUEST_URI} !^/subfolder/ # Don’t change this line. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Change ’subfolder’ to be the folder you will use for your main domain. RewriteRule ^(.*)$ /subfolder/$1 # Change yourdomain.com to be your main domain again. # Change ’subfolder’ to be the folder you will use for your main domain # followed by / then the main file for your site, index.php, index.html, etc. RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$ RewriteRule ^(/)?$ subfolder/index.php [L] |
subfolder替换你在public_html/下建立的目录,yourmaindomain.com替换为你的域名。
Monitor Your Web Site 24/7 - Receive email and SMS alerts anytime your web site goes down.

在程序根目录下添加.htaccess,内容如下:
RewriteEngine on
RewriteRule ^$ html/ [L]
RewriteRule (.*) html/$1 [L]
在html目录添加.htaccess如下内容:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
最近在玩bluehost,百度上看到你的帖子。
我在自己的上面试了试,但只有主页可以打开,
其他页面却访问不了,试了好久,依然不行。
希望能能帮到我。
我用了Zend Framework
QQ: 3912032