.htaccess 应用于错误的域名

.htaccess 应用于错误的域名

我已经像这样配置了我的 Apache:

<VirtualHost *:80>
  ServerName www.th3falc0n.de
  ServerAlias th3falc0n.de *.th3falc0n.de
  DocumentRoot /var/www/html/th3falc0n

    <Directory /var/www/html/th3falc0n>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:80>
  ServerName www.lolhens.org
  ServerAlias lolhens.org *.lolhens.org
  DocumentRoot /var/www/html/lolhens

    <Directory /var/www/html/lolhens>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>

我在 /var/www/html/th3falc0n 中有一个 .htaccess,它将 th3falc0n.de 重定向到 th3falc0n.de/p/home 和一些其他内容。但是,这些规则也适用于 lolhens.org,这不是预期的行为。我有什么错?我怎样才能使 .htaccess 仅适用于 th3falc0n.de?

apache2ctl -S 的输出

root@v36448:~# apache2ctl -S
VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.th3falc0n.de (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost www.th3falc0n.de (/etc/apache2/sites-enabled/000-default.conf:1)
                 alias th3falc0n.de
                 wild alias *.th3falc0n.de
         port 80 namevhost www.lolhens.org (/etc/apache2/sites-enabled/000-default.conf:15)
                 alias lolhens.org
                 wild alias *.lolhens.org
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

我收到了多个将 .htaccess 内容移到站点配置中的建议:这不是一个选项,因为管理 lolhens.org 的用户不得访问服务器配置,但能够使用 .htaccess,并且我想让所有可能的用户保持一致。

编辑:

在发现之后,http://www.lolhens.org.htaccess 没有这个问题,但它会发生在http://lolhens.org我尝试了另一个这样的配置:

<VirtualHost *:80>
  ServerName th3falc0n.de
  ServerAlias *.th3falc0n.de
  DocumentRoot /var/www/html/th3falc0n

    <Directory /var/www/html/th3falc0n>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>

<VirtualHost *:80>
  ServerName lolhens.org
  ServerAlias *.lolhens.org
  DocumentRoot /var/www/html/lolhens

    <Directory /var/www/html/lolhens>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>

但结果还是一样。www.lolhens.org 按预期工作,而 lolhens.org 则不然。

答案1

如果 www.lolhens.org 的任何内容是由 /var/www/html/th3falc0n 提供的,那么即使用户要求使用不同的域名,那里的 .htaccess 文件也会受到尊重。

Iain 是对的:由于您显然有权访问配置文件,最简单的解决方案是删除 .htaccess 文件,将其指令移至 www.th3falc0n.de 的 VirtualHost,然后通过设置禁用 .htaccess AllowOverride none。请参阅Apache htaccess 文件教程

答案2

我刚刚发现,问题出在我本地浏览器的缓存上,它保存了 lolhens.org 的重定向。第二个配置现在可以正常工作了。

相关内容