主域 .htaccess 内的共享托管 .htaccess

发布于 2024-12-09 12:34:35 字数 2796 浏览 0 评论 0原文

我很抱歉这个可能被认为是令人困惑的标题;但又想到别无选择。我需要知道多级文件三个系统级别的主要级别上的 .htaccess 如何影响以下级别的 .htaccess 文件的行为;以及其他级别的 .htaccess 文件如何影响非主域内的行为。

我通过共享托管帐户托管多个网站。

假设cpanel文件三系统结构。

从 public_html 我有主域,该目录包含一个 .htaccess 文件。然后,在三个文件结构中,我有其他域,我将其称为辅助域,每个域都有自己的 .htaccess

如果辅助域没有 .htacess,则来自主域的 .htaccess 会影响 url 的行为域分为文件三层结构。

我想确保所有 www.domain.com 都转到domain.com(至少来自我当前的服务提供商;因为,我与另一个服务提供商在一起,但情况并非如此。任何级别的.htaccess 都不会影响其他人)

我想要将 www.domain.com 重定向到 domain.com

主级别 .htaccess 通过以下代码实现了我对主域的目标:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.primarydomain.com [NC]
RewriteRule ^(.*)$ http://primarydomain.com/$1 [L,R=301]

并且我对辅助域进行了尝试和错误,试图

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.secondarydomain.com [NC]
RewriteRule ^(.*)$ http://secondarydomain.com/$1 [L,R=301]

使用 .htaccess 内的 代码实现相同的目标在主域内级别,以及文件三系统的第二级别,我无法获得所需的结果

为了更好地说明,我添加了三文件系统:

cpanel_account

   public_html
      .htaccess
      index.php
      index.html
      secondarydomain.com
         .htacess
         index.php
         index.html

How can I redirect www.secondarydomain.com 从 .htaccess 调用到 secondarydomain 无论主域级别或者文件三层结构的二级域级别?

谢谢,

[更新]

嗯,很好,我发布了问题 b/c,现在我做了更多研究,我发现:

当我查看其中一个共享托管帐户的 .htaccess 时,我发现了以下第一级的修改后的 .htacess 代码public_html

# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName PrimaryDomain.com
AuthUserFile /home/USER/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/USER/public_html/_vti_pvt/service.grp

<files *.js.gz>
  AddType "text/javascript" .gz
  AddEncoding gzip .gz
</files>
<files *.css.gz>
  AddType "text/css" .gz
  AddEncoding gzip .gz
</files>
RewriteEngine on
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
#make sure there's no trailing .gz on the url
ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$
#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f
#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [QSA,L] 

以及是否添加此代码到二级域级别(即 public_html/secondarydomain.com/.htacess)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.secondarydomain.com [NC]
RewriteRule ^(.*)$ http://secondarydomain.com/$1 [L,R=301]

(无论我是否添加此代码,请重复

)域,所有域请求(即 www.anyofmydomainshostedhere.com)都被重定向到非 www anyofmydomainshostedhere.com

:?

I'm sorry for what can be considered a confusing title; but thought of no alternative. And I need to know how .htaccess on a primary level of multiple level file three system level affects the behavior of the .htaccess files of the levels below; as well as how .htaccess files from the other levels affect behavior within the non-primary domains.

I am hosting multiple websites from a shared hosting account.

Assume cpanel file three system structure.

From public_html I have the primary domain, this directory contains a .htaccess file. Then, down the three file structure I have other domains, which I will refer to as secondary domains, and each has its own .htaccess

if a secondary domain has no .htacess, the .htaccess from the primary domain affects the behavior of url's of domains down the file three structure.

I want to ensure that all www.domain.com go to domain.com (at least from my current service provider; because, I was with another and this was not the case. .htaccess from whatever level do not affect others)

I wanted to redirect www.domain.com to domain.com

The primary level .htaccess achieves my goal for the primary domain through the following code:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.primarydomain.com [NC]
RewriteRule ^(.*)$ http://primarydomain.com/$1 [L,R=301]

And I have trial and error for secondary domain trying to achieve the same with code

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.secondarydomain.com [NC]
RewriteRule ^(.*)$ http://secondarydomain.com/$1 [L,R=301]

WITHIN the .htaccess that is within the primary domain leve, and the second level of the file three sytem and I am unable to get the desired result

For better ilustration I add a three file system:

cpanel_account

   public_html
      .htaccess
      index.php
      index.html
      secondarydomain.com
         .htacess
         index.php
         index.html

How can I redirect www.secondarydomain.com calls to secondarydomain from the .htaccess whether primary domain level or secondary domain level of the file three structure?

Thank you,

[UPDATE]

Well, good I posted the question b/c now that I do more research I find:

as i look over the .htaccess of one of one shared hosted account i found the following modified .htacess code for first level public_html

# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName PrimaryDomain.com
AuthUserFile /home/USER/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/USER/public_html/_vti_pvt/service.grp

<files *.js.gz>
  AddType "text/javascript" .gz
  AddEncoding gzip .gz
</files>
<files *.css.gz>
  AddType "text/css" .gz
  AddEncoding gzip .gz
</files>
RewriteEngine on
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
#make sure there's no trailing .gz on the url
ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$
#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f
#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [QSA,L] 

And whether I add or not this code to second levels domain level (i.e. public_html/secondarydomain.com/.htacess)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.secondarydomain.com [NC]
RewriteRule ^(.*)$ http://secondarydomain.com/$1 [L,R=301]

(REPEAT WHETHER I ADD THIS CODE OR NOT)

the domains, all domain requests (i.e. www.anyofmydomainshostedhere.com) are redirected to non-www anyofmydomainshostedhere.com

:?

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

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

发布评论

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

评论(1

那请放手 2024-12-16 12:34:35

如果我正确理解目标,您需要将 secondarydomain.com 重写放在 secondarydomain.com 文件夹中。原因是域会立即定向到该文件夹​​,而不会在 public_html 文件夹中看到 .htaccess 文件。

我对你提到的级联 .htaccess 事情不太乐观 - 这将是一个相当有趣的服务器配置,我不知道它是如何工作的,因为 .htaccess 应该是目录级别的。

If I'm understanding the goal correctly, you need to place the secondarydomain.com rewrite in the secondarydomain.com folder. The reason for this is that the domain is directed immediately to the folder and never sees the .htaccess file in the public_html folder.

I'm not too positive about the cascading .htaccess thing you mentioned - that'd be a rather interesting server configuration and I've got no clue how that would work since .htaccess is supposed to be directory-level.

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