更改托管域的文档根目录?

时间:2011-04-11 14:54:12

标签: .htaccess subdomain redirect subdirectory addon-domain

我遇到了一个问题,即我的网站托管服务商似乎没有提供插件域名。

我目前有一个指向我的名字服务器的域名。

我进入cPanel添加一个指向子目录的插件域,但cPanel中可用的所有内容都是在文件根目录中停放域,即“public_html /”。

因此来自停放域名的流量会得到错误的内容,这显然不太好。

我觉得这是不可能的,但是我可以将托管域文档根目录从“public_html /”更改为“public_html / sub-directory”吗?

或者我可以编辑.htaccess文件以将流量从托管域重定向到子目录吗?

基本上我想要这个地址; www.parked-domain.com /

显示此子目录的内容; www.first-domain.com/parked-directory

我希望这是可能的,否则我需要看一个新的网络主机。

此致

迪安。

3 个答案:

答案 0 :(得分:9)

将以下内容添加到.htaccess文件中:

RewriteRule ^parked-directory - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com$ [NC]
RewriteRule ^(.*)$ parked-directory/$1 [L]

答案 1 :(得分:4)

虽然不赞成,但可以使用mod_rewrite动态设置托管域子主机。

以下是使用动态格式通过mod_rewrite进行多主机的.htaccess示例,该动态格式需要parked-domain-name = sub-folder-name,并覆盖您网站上被重定向或忽略的其他托管域。

# tell mod_rewrite to activate and give base for relative paths
  RewriteEngine on
  RewriteBase   /

# permanent redirect of unused parked domains so they do not try to resolve.
# only use this redirect if you want multiple names to point to another.
# otherwise, replace the rewrite rule with: RewriteRule . - [F,L]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain1\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain2\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain3\.com$ [NC,OR]
  RewriteCond %{HTTP_HOST}   ^(www\.)?parked-domain4\.com$ [NC]
  RewriteRule ^(.*)$         http://main-site.com/$1 [L,R=301]

# if you have an active site in hosting root folder,
# then tell it not to look for a subfolder by skipping next rule
  RewriteCond %{HTTP_HOST}   ^(www\.)?main-site\.com [NC]
  RewriteRule ^(.*)$         - [S=1]

# the domain-name = sub-folder automation
# thus parked-domain5.com in /parked-domain5/
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com
  RewriteCond %{REQUEST_URI} !^/%1
  RewriteRule ^(.*)$         %1/$1 [L]

# if you're hosting wordpress sites, this is a tweaked variant of the WP code.
# add the rest of this example only if:
#   1. main-site.com is a WP site
#   2. you remove .htaccess in subfolders
# if (1.) true, yet keeping subfolder .htaccess, uncomment next 2 lines:
# RewriteCond %{HTTP_HOST} !^(www\.)?main-site\.com [NC]
# RewriteRule ^(.*)$ - [S=1]
#### BEGIN WordPress, improved
# if this request is for "/" or has already been rewritten to WP 
  RewriteCond $1 ^(index\.php)?$ [OR]
# or if request is for image, css, or js file 
  RewriteCond $1 \.(gif|jpg|jpeg|png|css|js|ico)$ [NC,OR]
# or if URL resolves to existing file 
  RewriteCond %{REQUEST_FILENAME} -f [OR]
# or if URL resolves to existing directory 
  RewriteCond %{REQUEST_FILENAME} -d
# then skip the rewrite to WP 
  RewriteRule ^(.*)$ - [S=1]
# else rewrite the request to WP 
  RewriteRule . /index.php [L]
# END WordPress

答案 2 :(得分:2)

而不是使用“停放的域名”,请使用插件域 - 这里只是您想要指向新“停放”域名的public_html /子目录的根目录...