我有两个域具有相同的文档根。根据要求,我希望两个域都应该有自己的.htaccess文件。他们可以通过哪种方式实现这一目标?
下面的示例包含两个域,我们必须根据域选择查询参数。
RewriteCond %{HTTP_HOST} ^www\.site1\.example [NC]
RewriteRule ^(.*)$ index.php?domainname=site1 [NC,QSA]
RewriteCond %{HTTP_HOST} ^www\.site2\.example [NC]
RewriteRule ^(.*)$ index.php?domainname=site2 [NC,QSA]
但是不可能在同一个文件夹中添加多个.htaccess
文件。
除了常见的RewriteCond
遮盖之外,还有更多的选择。特别是如果你需要的不仅仅是mod_rewrite指令,那么使用它是有意义的:
AcesssFilename
。
<VirtualHost *:80>
AccessFileName .htaccess2
<If>
section分开一个.htaccess:
<If "%{HTTP_HOST} =~ 'www2'">
Include .htaccess2
# or a bunch of RewriteRules here
</If>
对于核心指令,我还建议在虚拟主机配置中设置它们。但对于基本的重定向,次要的.htaccess.domain2
可能会这样做。