把主域名绑定到子目录

| |
[2007/09/27 00:04 | 分类: 网站设计 | by 小辛 ]

先简单把操作方法说明一下:
1. 编辑主目录的.htaccess文件,清空里面的内容(如果你看得懂,就自己修改要保留有用的,不要全删掉)
2. 拷贝下面蓝色的代码,所有以#开头的语句都是注释,告诉你怎么改,如果你看不懂,可以删除掉那个以#开头的行
3. 把里面的所有 yourmaindomain.com 修改为你的域名
4. 把里面的所有 subfolder 修改为你希望放到的文件夹的名称
5. 保存文件,覆盖原来的那个.htaccess
6. 再试试访问你的网站,已经指向到你的子目录了,如果你还没有建目录,就会出现404错误。这几说明这个设置已生效了。
7. 把你网站根目录原来的所有文件(除了根目下的.htaccess,这个一定要放在根目录) 移到你的子目录。所有工作就完成了,根目录干净了,爽啊。
8. 补充,修改的时候要仔细,里面用到了复杂的正则表达式,修改的时候里面所有的各种符号,空格都要原样保留,改的时候看仔细了,切记。
.htaccess的功能真的很强大啊,不过使用也很复杂,关那个正则表达式就搞死人了。
资料来自于: BlueHost Support Center
Problem
The main domain on the hosting account uses the public_html folder for all of its Web site files. Any addon domains use subfolders inside the public_html folder. In order to also set up your main domain to use a subfolder on your hosting account you will need to set up a redirect in the .htaccess file in the public_html folder so that the server knows that any request for your main domain will be redirected to a subfolder on public_html.
Visitors to your Web site will not be able to tell that your main domain is using a subfolder, they will still see the Web site address as http://www.yourdomain.com/page.html
Solution
# 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]
评论(0) | 引用(0) | 阅读(1281)
发表评论
昵称 [注册]
密码 游客无需密码
网址
电邮
打开HTML 打开UBB 打开表情 隐藏 记住我