.htaccess 从文件夹访问多个子域
我正在处理以下问题: 我有一个主域“example.com”和多个子域:.htaccess 从文件夹访问多个子域,.htaccess,routing,.htaccess,Routing,我正在处理以下问题: 我有一个主域“example.com”和多个子域: one.example.com two.example.com three.example.com 等等。在服务器上 我在文件夹中有此子域的内容: ./one/ -> one.example.com ./two/ -> two.example.com ./three/ -> three.example.com 等等 因此,为了将这些文件夹中的内容提供给子域,我使用以下htaccess文件
one.example.com
two.example.com
three.example.com
等等。在服务器上
我在文件夹中有此子域的内容:
./one/ -> one.example.com
./two/ -> two.example.com
./three/ -> three.example.com
等等
因此,为了将这些文件夹中的内容提供给子域,我使用以下htaccess文件:
RewriteCond %{HTTP_HOST} ^one.example.com [NC]
RewriteCond %{REQUEST_URI} !^/one/.*
RewriteRule ^(.*) /one/$1 [L]
它工作正常,但我的子域内容也可以从URL访问:
one.example.com/one/my-content
比如
one.example.com/my-content
等等,所以它是双面的
这是我需要解决的一个问题
其次,example.com的内容可以从
whatever.example.com
(a.example.com, b.example.com etc.)
同样的,杜普利西
所以我的问题是:如何重定向/禁用正在创建duplicite的URL
非常感谢,我尝试了很多版本的代码,但都没有效果。对于第一个问题,您可以添加一条规则,将任何请求重定向到该文件夹,并将该目录重定向到不存在的页面(因此会出现404错误)
对于第二个问题,这不应该发生,因为当您请求a.example.com/folder/file.html时,它会在内部重定向到a.example.com/a/folder/file.html(无法获取“a”的父目录中的内容)我解决了这个问题,将所有到子域的请求重定向到该文件夹,将所有到基域的请求重定向到另一个,如下所示:
RewriteCond %{HTTP_HOST} ^one\. [NC]
RewriteRule (.*) /one$1 [L]
RewriteCond %{HTTP_HOST} ^two\. [NC]
RewriteRule (.*) /two$1 [L]
RewriteRule (.*) /zero$1
这似乎很有效,但我也在浏览器上修改我的URL。如何避免这种情况发生?谢谢您的回答。我试图使用你的代码,但没有结果。我忘了提一下,我使用动态创建子域(CNAME中的DNS记录*),这可能就是问题所在,因为有时它的行为很奇怪,因为我对此没有经验……你不应该回答这个问题,同时问后续问题。您的后续问题可能不会被看到或回答。感谢@psubsee2003的回复。我将适当地发布另一个问题。
RewriteCond %{HTTP_HOST} ^one\. [NC]
RewriteRule (.*) /one$1 [L]
RewriteCond %{HTTP_HOST} ^two\. [NC]
RewriteRule (.*) /two$1 [L]
RewriteRule (.*) /zero$1