更改停放域的文档根目录?

发布于 2024-10-31 14:15:12 字数 452 浏览 0 评论 0原文

我遇到了一个问题,即我的网络主机没有提供插件域。

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

我进入 cPanel 添加一个指向子目录的插件域,但 cPanel 中可用的只是将域停放在文档根目录“public_html/”处。

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

我感觉这是不可能的,但是我可以将停放域文档根从 'public_html/' 更改为 'public_html/sub-directory' 吗?

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

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

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

我希望这是可能的,否则我需要寻找新的网络主机。

问候,

迪恩。

I have run into a problem which is that my web host doesn't appear offer addon domains.

I currently have a domain name pointing to my name servers.

I went into cPanel to add an addon domain that points to a sub-directory, but all that is available in cPanel is to park domain at the document root which is 'public_html/'.

So traffic coming from the parked domain would get the wrong content, which is obviously not good.

I get the feeling that this isn't possible, but can I change the parked domain document root from 'public_html/' to 'public_html/sub-directory' ?

Or perhaps can I edit the .htaccess file to redirect traffic from the parked domain to the sub-directory?

Basically I want this address; www.parked-domain.com/

To show the content of this sub-directory; www.first-domain.com/parked-directory

I hope this is possible otherwise I need to look at a new web host.

Regards,

Dean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

指尖上的星空 2024-11-07 14:15:12

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

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

Add the following to your .htaccess file:

RewriteRule ^parked-directory - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?parked-domain\.com$ [NC]
RewriteRule ^(.*)$ parked-directory/$1 [L]
锦爱 2024-11-07 14:15:12

虽然令人皱眉,但可以使用 mod_rewrite 动态设置您的停放域子主机。

以下是通过 mod_rewrite 使用动态格式进行多主机的 .htaccess 示例,该格式需要停放域名 = 子文件夹名称,并涵盖您网站上被重定向或忽略的其他停放域。

# 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

While frowned upon, it is possible to dynamically set up your parked domain sub-hosts using mod_rewrite.

Here's a .htaccess sample for multihosting via mod_rewrite using a dynamic format that requires parked-domain-name = sub-folder-name, and covers other parked domains on your site being redirected or ignored.

# 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
可是我不能没有你 2024-11-07 14:15:12

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

instead of using "parked domain", use the addon domain - and here just the root directory to public_html/sub-directory where you want to point your new "parked" domain...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文