【问题标题】:Apache2 - Directory URL without trailing slash redirecting to different URLApache2 - 没有尾随斜杠的目录 URL 重定向到不同的 URL
【发布时间】:2017-08-02 03:44:16
【问题描述】:

我在使用 Apache2 自动加载子目录中的 index.php 时遇到问题。 这是我在连接时在浏览器控制台中看到的:

GET http://example.com/login                     HTTP 301 Moved Permanently
GET http://10.0.3.10/login/
Connection Timed Out

当我输入http://example.com/login/ 时,它按预期工作。还, 根目录正确重定向到 index.php。

我对这个主题还很陌生,希望得到任何帮助。

默认虚拟主机设置:

#NameVirtualHost *:80
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example.com/
        ServerAlias www.example.com/

        DocumentRoot /var/www/example.com/
        <Directory />
                AllowOverride All
                DirectoryIndex index.php
        </Directory>
        <Directory /var/www/example.com/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
...

httpd.conf:

<IfModule dir_module>
DirectoryIndex index.php
</IfModule>

未使用 .htaccess 文件。

【问题讨论】:

    标签: php apache redirect apache2


    【解决方案1】:

    我认为您的请求是由没有 ServerName 的虚拟主机处理的,并且在启动时 httpd 可能会警告您找不到本地 IP (10.0.3.10) 的默认主机名

    尝试从您的 ServerName 和 ServerAlias 中删除尾部斜杠。如果您的 ServerName 或 ServerAlias 与系统主机名匹配,您将需要做更多的事情——即将一个虚拟的 ServerName 添加到您的默认 vhost。

    【讨论】:

    • 实际上我在默认文件中配置了虚拟主机,因为我不打算配置其他网站。这是错的吗?我尝试删除尾部斜杠,但没有帮助。
    • 使用默认值没问题,但那些斜线肯定是错误的。您是否正在通过可能将您的主机标头更改为该 IP 的代理?
    • 据我所知,我不会通过代理。
    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 2012-02-01
    • 2013-02-15
    • 1970-01-01
    相关资源
    最近更新 更多