raksmart活动促销

分享

写回答

发帖

关于将主域名绑定到子目录的问题!

BlueHost BlueHost 7645 人阅读 | 16 人回复

发表于 2011-9-4 21:50:40 | 显示全部楼层 |阅读模式

知道官方的方法是添加如下代码

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

但现在我的用的是wordpress,无论我如何设置,以上方法始终无效,情况就是页面所有脚本文件都重定向到首页了,如css/js等文件,导致整个页面都 不能正常显示,最后没办法,只好将程序全部放到根目录下运行了

以下是我的.htaccess

RewriteEngine on

# 设置重写条件
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
# Change ‘subfolder’ to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/wwwroot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# 设置重写规则
RewriteRule ^(.*)$ /wwwroot/index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ wwwroot/index.php [L]

弄了一天都没能搞定,郁闷~~

回答|共 16 个

lpj

发表于 2011-9-5 09:11:01 | 显示全部楼层

将带 #  号的语句都去掉,主域名绑定子目录注意事项:
1.、在根目录下创建.htaccess文件;
2、网站程序上传到子目录中,如wordpress文件夹
3、在.htaccess文件中添加 1楼代码,修改
RewriteRule ^(.*)$ /subdirectory/$1
RewriteRule ^(/)?$ subdirectory/index.php [L]
中的子目录文件名为wordpress,后面的index.php可以不要。
根目录下只要存在.htaccess文件即可,其他的都放在子目录文件夹中。
RAKSmart
回复 支持 反对

使用道具 举报

winsonet

发表于 2011-9-5 10:20:24 | 显示全部楼层

今天又尝试了一次,还是不行,情况一样,以下是完整的代码:

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{REQUEST_URI} !^/wwwroot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wwwroot/$1
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteRule ^(/)?$ wwwroot/index.php [L]
回复 支持 反对

使用道具 举报

lpj

发表于 2011-9-5 10:29:29 | 显示全部楼层

域名也修改了吗?^(www.)?mydomain.com$
回复 支持 反对

使用道具 举报

哥是浮云

发表于 2011-9-5 10:36:09 | 显示全部楼层

将mydomain.com换成你自己的域名,还有注意.htaccess的位置,如果是在子目录里面注意RewriteEngine on要添加RewriteEngine on  /子目录名
回复 支持 反对

使用道具 举报

lpj

发表于 2011-9-5 10:49:31 | 显示全部楼层

RewriteEngine on就可以了
回复 支持 反对

使用道具 举报

winsonet

发表于 2011-9-5 10:49:56 | 显示全部楼层

是的,域名当然改了:
添加了 RewriteEngine on  /子目录名   后,现在首页可以访问,只是文章页面全部出现 404错误了
回复 支持 反对

使用道具 举报

winsonet

发表于 2011-9-5 10:53:12 | 显示全部楼层

哦,不关事,现在其他页面一直是404错误,就算不加上面那句也一样的,奇怪,这不会是有缓冲吧?之前根本是不行的

以下是完整的代码:

# Use PHP5CGI as default
AddHandler fcgid-script .php


RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?coderblog.in$
RewriteCond %{REQUEST_URI} !^/wwwroot/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wwwroot/$1
RewriteCond %{HTTP_HOST} ^(www.)?coderblog.in$
RewriteRule ^(/)?$ wwwroot/index.php [L]

[ 本帖最后由 winsonet 于 2011-9-5 10:58 AM 编辑 ]
回复 支持 反对

使用道具 举报

lpj

发表于 2011-9-5 11:29:36 | 显示全部楼层

.htaccess功能是实现了,正常情况是,访问时带有子目录文件夹名称,你的没有,在网站后台中网站地址中添加子目录名称试试。
回复 支持 反对

使用道具 举报

winsonet

发表于 2011-9-5 12:09:48 | 显示全部楼层

后台地址改后,加多子目录名,当然是可以访问的,因为这就等于直接访问子目录了,但这也达不到真正的目的,就算不设置转向,这样应该也是可以访问的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则