`
xinlanzero
  • 浏览: 246270 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Godaddy 主域名绑定到子目录及管理子域名

 
阅读更多

Godaddy 是世界第一大域名注册商,进军主机领域以后发展迅速,据多家监测机构显示,放置在Godaddy上的网站数量已经越居第一位。

Godaddy同时提供linux主机,Windows主机,VPS以及独立主机全线主机产品,各种需求的客户在这里都可以找到适合自己的产品。美国主机评论家多次评为第一名。

Godaddy同时提供独立IP,SSL证书,帮助客户快速打造自己的电子商务网站。

Godaddy 管理子域名子目录

进入Godaddy的 Hosting Control Center > Domain Management 域名管理(https://hostingmanager.secureserver.net/DomainManagement2.aspx),见下图可以管理子域名,可以配置子域名到各个目录下。

Godaddy的 Hosting Control Center 域名管理 image

但是其添加子域名时,Subdomain不能添加www或者为空,说明这个域名管理不能管理主域名。

Godaddy Adding a subdomain to this hosting image

注意:添加域名时,可以选择其文件夹,默认是选择一个和子域名名称一样的文件夹,建议选择或者创建一个新的文件夹。

Godaddy主域名子目录问题

显然我们无法控制主域名绑定到一个子目录上去。根据Godaddy实现301跳转的思想,我决定使用.htaccess文件实现主域名绑定到子目录上去。

 

Godaddy 主域名绑定到子目录

编辑html目录下的.htaccess文件,加入如下语句。如果html下没有.htaccess文件,新建一个即可。

注意:将yourmaindomain.com修改为你的域名,将subfolder修改为你要指向的html下的子目录.最后一行中的index.php修改为你的网站的主页名称.(修改粗体表示的内容,其他内容不要改动)

# .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.

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]

这只是将主域名绑定到了子目录,但是要让其正常运行还得看你的子目录程序如何处理。

Godaddy Drupal 子目录映射到主域名

  • 第一步

编辑 html/subfolder (这里是存放drupal程序的地方) 目录下的.htaccess文件, 大概在110行,修改为如下代码:

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /subfolder

这里drupal已经给你说明了还给你注释的很清楚,如何把主域名后面的subflolder去掉。

  • 第二步

设置 drupal/sites/all/default/settings.php (drupal配置文件) 的基础URL为你的主域名yourmaindomain.com

/**
* Base URL (optional).
*
* If you are experiencing issues with different site domains,
* uncomment the Base URL statement below (remove the leading hash sign)
* and fill in the absolute URL to your Drupal installation.
*
* You might also want to force users to use a given domain.
* See the .htaccess file for more information.
*
* Examples:
*   $base_url = ‘http://www.example.com’;
*   $base_url = ‘http://www.example.com:8888′;
*   $base_url = ‘http://www.example.com/drupal’;
*   $base_url = ‘https://www.example.com:8888/drupal’;
*
* It is not allowed to have a trailing slash; Drupal will add it
* for you.
*/
$base_url = ‘http://www.yourmaindomain.com’;  // NO trailing slash!

注释里已经说明的很清楚,这个需要和.htaccess 一起搭配其使用。

测试

好的,首先清空你浏览器的缓存,或者将浏览器关闭后重新启动。在地址栏输入http://www.yourmaindomain.com你将会看到和http://www.yourmaindomain.com/subflolder一模一样。

关于清空浏览器的方法,请查看我的另外一篇文章:Firefox和IE浏览器清除缓存方法

以上方法不经支持在Godaddy,同样在cpanel 中有效,请在评论中告诉我你在哪儿实现了。

声明:本站遵循署名-非商业性使用-相同方式共享 3.0共享协议. 转载请注明转自LixiPHP
  • 大小: 114.8 KB
  • 大小: 55.2 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics