生命不息,奋斗不止/创造价值-传递价值-获得价值
所谓迷茫,就是才华配不上梦想 每一个让你难堪的现在,都有一个不够努力的曾经

bluehost主域名跳转到子目录

How to host the Primary Domain from a subfolder (.htaccess)

How to host the Primary Domain from a subfolder (.htaccess)SummaryThe public_html directory for all of its Web site files. Addon domains use sub directories inside the public_html directory. In order to also set up your main domain to use a subdirectory 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 subdirectory on public_html.

  • Locating the .htaccess file in the File Manager
  • Modifying the .htaccess
  • When using WordPress
  • Joomla, Drupal and WordPress

Locating the .htaccess file in the File Manager

To begin you will need to open the .htaccess file located in your public_html folder. Because this file is, by default, not visible, please follow the instructions below to locate and open this file.

  1. Log in to the Bluehost cPanel.
  2. Scroll down to the Files section.
  3. Click the File Manager icon.
  4. Check the View Hidden Files checkbox.
  5. You are working with your primary domain, so select the WebRoot (public_html/www) option.
  6. Right click the .htaccess and choose Code Editor

Modifying the .htaccess

The following code will need to be added to the .htaccess file in the public_html folder of your hosting account. You will need to insert the following code block and make modifications as noted in the (#) comments.

You will need to change the two instances of example.com to your domain, and the three instances of subdirectory to the folder where you want your site.

# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change ‘subdirectory’ to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don’t change the following two lines.
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 example.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.)?example.com$
RewriteRule ^(/)?$ subdirectory/index.html [L]

 

Visitors to your Web site will not be able to tell that your main domain is using a subdirectory, they will still see the Web site address as http://www.example.com/page.html.

Please note that this will not work with some website software. You may also need to modify the $base_url, $live_site or other configuration settings to finish the process.

Joomla, Drupal and WordPressIf you are using Joomla, Drupal or WordPress it is recommend that you not follow the instructions above, rather that you follow the instructions provided by in the official documentation. Please see the links below for instructions specific to the CMS you are using.

  • Drupal installed in subdirectory but made to appear in root
  • Joomla – Moving the site among directories/sub-directories
  • Giving WordPress Its Own Directory

转载自https://my.bluehost.com/cgi/help/347

 

 

 

Bluehost的主域名的目录默认是主机的根目录,如果我们要建多个网站,绑定多个域名的话,就会显示根目录很乱,不方便管理,所以一般将主域名映射到一个指定的文件夹。

Bluehost的主域名指向子目录文件夹方法:
1、假设你的域名是example.com,在根目录创建一个文件夹,例如:subdirectory ;
2、创建一个.htaccess文件,将下面代码复制到里面,上传到主机根目录,即public_html目录,注意是根目录;

# 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 example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/subdirectory/
# Don't change these 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 example.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.)?example.com$
RewriteRule ^(/)?$ subdirectory/ [L]

将以上代码中的域名、文件夹换成你自己的即可。主域名指向子目录后,根目录就会更清晰,管理更方便。

 

 

 

我的做法:

 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?sunixlight.com$
RewriteCond %{REQUEST_URI} !^/web/sunixlight
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /web/sunixlight/$1
RewriteCond %{HTTP_HOST} ^(www.)?sunixlight.com$
RewriteRule ^(/)?$ web/sunixlight/index.php [L]

赞(0)
未经允许不得转载:jack361博客 » bluehost主域名跳转到子目录

如果你爱我或恨我,请↓

联系我