---
title: "Bluehost 主域名映射到子目录文件夹的方法 .htaccess"
author: "xinlanzero"
date: "2011-09-11T16:15:00Z"
tags: []
categories: ["Web前端"]
slug: "bluehost-htaccess"
draft: false
lastmod: "2011-09-11T16:15:00Z"
id: 1170149
url: "https://xinlanzero.iteye.com/blog/1170149"
---

在bluehost上购买了空间，如何让一个主域名访问子目录呢，最简单方法是用 .htaccess 来进行限制。

在bluehost 的/public\_html 新建立一个 .htaccess 文件，如果没有这个文件的话。

拷贝下面代码放到 .htaccess 文件里

\# Bluehost.com  
\# .htaccess main domain to subdirectory 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 'subdirectory' to be the directory you will use for your main domain. 需要指定的子目录  
RewriteCond %{REQUEST\_URI} !^/subdirectory/  
\# Don't change this line.  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteCond %{REQUEST\_FILENAME} !-d  
\# Change 'subdirectory' to be the directory you will use for your main domain. 需要指定的子目录  
RewriteRule ^(.\*)$ /subdirectory/$1  
\# Change yourdomain.com to be your main domain again.  
\# Change 'subdirectory' to be the directory 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 ^(/)?$ subdirectory/index.php \[L]