Php 未为一个URL计算htaccess

Php 未为一个URL计算htaccess,php,apache,.htaccess,Php,Apache,.htaccess,目前我的web服务器有一个有趣的问题,我找不到解决方案,希望您的帮助 我已经在Arch Linux上设置了一个Apache服务器,我正在使用VirtualDocumentRoot创建“开发域”。配置文件如下所示: ServerName localhost <VirtualHost *:80> UseCanonicalName Off DocumentRoot /srv/http/ ServerName localhost <Directory

目前我的web服务器有一个有趣的问题,我找不到解决方案,希望您的帮助

我已经在Arch Linux上设置了一个Apache服务器,我正在使用VirtualDocumentRoot创建“开发域”。配置文件如下所示:

ServerName localhost
<VirtualHost *:80>
    UseCanonicalName Off
    DocumentRoot /srv/http/
    ServerName localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3
    CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /srv/http/%-2/webroot/
    VirtualScriptAlias /srv/http/%-2/cgi-bin/
    DocumentRoot /srv/http/

    ServerAlias *.localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon

</VirtualHost>
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /something/404 HTTP/1.1" 200 -
[Fri Oct 02 06:00:00.919667 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add path info postfix: /srv/http/projectname/webroot/something -> /srv/http/projectname/webroot/something/404
[Fri Oct 02 06:00:00.919721 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/something/404 -> something/404
[Fri Oct 02 06:00:00.919736 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'something/404'
[Fri Oct 02 06:00:00.919761 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] rewrite 'something/404' -> 'index.php'
[Fri Oct 02 06:00:00.919773 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add per-dir prefix: index.php -> /srv/http/projectname/webroot/index.php
[Fri Oct 02 06:00:00.919784 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip document_root prefix: /srv/http/projectname/webroot/index.php -> /index.php
[Fri Oct 02 06:00:00.919793 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Oct 02 06:00:00.919839 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/index.php -> index.php
[Fri Oct 02 06:00:00.919851 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'index.php'
[Fri Oct 02 06:00:00.919868 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] pass through /srv/http/projectname/webroot/index.php
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /error/404 HTTP/1.1" 404 1131
Alias /error/ "/usr/share/httpd/error/"
所以如果我访问http://localhost 它会告诉我所有的项目。点击一个项目,我可以看到所有的文件夹,点击“webroot”,我会看到项目的最终主页

由于VirtualDocumentRoot配置,我也可以直接访问,它将服务于/srv/http/projectname/webroot的内容,这使我能够像在“真实条件”中一样测试网页

对于其中的一个项目,我创建了一个MVC系统,它像Wordpress一样构建。如果调用类似于服务器的东西,则应该为文件/srv/http/projectname/webroot/index.php提供服务,并将foo和bar作为参数传递给索引文件。 这是通过将.htaccess文件放入包含以下内容的webroot文件夹来完成的:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
error.log如下所示:

ServerName localhost
<VirtualHost *:80>
    UseCanonicalName Off
    DocumentRoot /srv/http/
    ServerName localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3
    CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /srv/http/%-2/webroot/
    VirtualScriptAlias /srv/http/%-2/cgi-bin/
    DocumentRoot /srv/http/

    ServerAlias *.localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon

</VirtualHost>
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /something/404 HTTP/1.1" 200 -
[Fri Oct 02 06:00:00.919667 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add path info postfix: /srv/http/projectname/webroot/something -> /srv/http/projectname/webroot/something/404
[Fri Oct 02 06:00:00.919721 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/something/404 -> something/404
[Fri Oct 02 06:00:00.919736 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'something/404'
[Fri Oct 02 06:00:00.919761 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] rewrite 'something/404' -> 'index.php'
[Fri Oct 02 06:00:00.919773 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add per-dir prefix: index.php -> /srv/http/projectname/webroot/index.php
[Fri Oct 02 06:00:00.919784 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip document_root prefix: /srv/http/projectname/webroot/index.php -> /index.php
[Fri Oct 02 06:00:00.919793 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Oct 02 06:00:00.919839 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/index.php -> index.php
[Fri Oct 02 06:00:00.919851 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'index.php'
[Fri Oct 02 06:00:00.919868 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] pass through /srv/http/projectname/webroot/index.php
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /error/404 HTTP/1.1" 404 1131
Alias /error/ "/usr/share/httpd/error/"
对于NOK,access.log如下所示:

ServerName localhost
<VirtualHost *:80>
    UseCanonicalName Off
    DocumentRoot /srv/http/
    ServerName localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3
    CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /srv/http/%-2/webroot/
    VirtualScriptAlias /srv/http/%-2/cgi-bin/
    DocumentRoot /srv/http/

    ServerAlias *.localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon

</VirtualHost>
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /something/404 HTTP/1.1" 200 -
[Fri Oct 02 06:00:00.919667 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add path info postfix: /srv/http/projectname/webroot/something -> /srv/http/projectname/webroot/something/404
[Fri Oct 02 06:00:00.919721 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/something/404 -> something/404
[Fri Oct 02 06:00:00.919736 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'something/404'
[Fri Oct 02 06:00:00.919761 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] rewrite 'something/404' -> 'index.php'
[Fri Oct 02 06:00:00.919773 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add per-dir prefix: index.php -> /srv/http/projectname/webroot/index.php
[Fri Oct 02 06:00:00.919784 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip document_root prefix: /srv/http/projectname/webroot/index.php -> /index.php
[Fri Oct 02 06:00:00.919793 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Oct 02 06:00:00.919839 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/index.php -> index.php
[Fri Oct 02 06:00:00.919851 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'index.php'
[Fri Oct 02 06:00:00.919868 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] pass through /srv/http/projectname/webroot/index.php
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /error/404 HTTP/1.1" 404 1131
Alias /error/ "/usr/share/httpd/error/"
并且error.log不包含任何内容

因此,您可能知道为什么只有在URL路径中使用“error”并与VirtualDocumentRoot一起使用时,才会触发此.htaccess


谢谢大家!

只有在URL中输入/error/something以及@anubhava的提示时才会发生,这一事实让我检查了Apache后台发生的一切。我真的找到了原因

在ArchLinux上使用Apache之前,我使用了Ubuntu。它在那里工作,所以我比较了所有的文件。 两个版本都有自定义错误页的配置文件

  • Ubuntu:/etc/apache2/conf可用/localized-error-pages.conf
  • Arch:/etc/httpd/conf/extra/httpd-multilang-errordoc.conf
这两个文件都有一行“/error/”的别名。在Arch中,它看起来像这样:

ServerName localhost
<VirtualHost *:80>
    UseCanonicalName Off
    DocumentRoot /srv/http/
    ServerName localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3
    CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /srv/http/%-2/webroot/
    VirtualScriptAlias /srv/http/%-2/cgi-bin/
    DocumentRoot /srv/http/

    ServerAlias *.localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon

</VirtualHost>
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /something/404 HTTP/1.1" 200 -
[Fri Oct 02 06:00:00.919667 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add path info postfix: /srv/http/projectname/webroot/something -> /srv/http/projectname/webroot/something/404
[Fri Oct 02 06:00:00.919721 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/something/404 -> something/404
[Fri Oct 02 06:00:00.919736 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'something/404'
[Fri Oct 02 06:00:00.919761 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] rewrite 'something/404' -> 'index.php'
[Fri Oct 02 06:00:00.919773 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add per-dir prefix: index.php -> /srv/http/projectname/webroot/index.php
[Fri Oct 02 06:00:00.919784 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip document_root prefix: /srv/http/projectname/webroot/index.php -> /index.php
[Fri Oct 02 06:00:00.919793 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Oct 02 06:00:00.919839 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/index.php -> index.php
[Fri Oct 02 06:00:00.919851 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'index.php'
[Fri Oct 02 06:00:00.919868 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] pass through /srv/http/projectname/webroot/index.php
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /error/404 HTTP/1.1" 404 1131
Alias /error/ "/usr/share/httpd/error/"
但是,对于Ubuntu,该行被注释,因此未启用。在原始Apache文件和Xampp中,默认情况下也会启用错误别名,但在Ubuntu和我的Web服务器上,默认情况下会禁用该别名

由于首先评估配置,URL将执行别名,并且在目标目录中既没有.htaccess文件,也没有名为“something”的文件或目录。因此,结果是一个错误页面。未计算my webroot目录中的.htaccess文件,因为服务器未访问该目录

我从我的Web服务器知道,我无法更改Apache配置本身,只能实现一个.htaccess文件

因此最好的解决方案是仅使用任何默认别名中未使用的目录名。我检查了不同Apache软件包的默认配置文件,以下是一些默认别名:

  • cgi箱
  • cgi酒吧
  • 医生
  • 错误
  • 图标
  • 手册
  • 上传

希望这些信息也能帮助其他人。

只有在URL中输入/error/something以及@anubhava的提示时才会发生这种情况,这让我检查了Apache后台发生的一切。我真的找到了原因

在ArchLinux上使用Apache之前,我使用了Ubuntu。它在那里工作,所以我比较了所有的文件。 两个版本都有自定义错误页的配置文件

  • Ubuntu:/etc/apache2/conf可用/localized-error-pages.conf
  • Arch:/etc/httpd/conf/extra/httpd-multilang-errordoc.conf
这两个文件都有一行“/error/”的别名。在Arch中,它看起来像这样:

ServerName localhost
<VirtualHost *:80>
    UseCanonicalName Off
    DocumentRoot /srv/http/
    ServerName localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3
    CustomLog /var/log/httpd/access_log combined
</VirtualHost>
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /srv/http/%-2/webroot/
    VirtualScriptAlias /srv/http/%-2/cgi-bin/
    DocumentRoot /srv/http/

    ServerAlias *.localhost

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /srv/http/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/httpd/error_log
    LogLevel warn rewrite:trace3

    LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
    CustomLog /var/log/httpd/access_log vcommon

</VirtualHost>
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /something/404 HTTP/1.1" 200 -
[Fri Oct 02 06:00:00.919667 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add path info postfix: /srv/http/projectname/webroot/something -> /srv/http/projectname/webroot/something/404
[Fri Oct 02 06:00:00.919721 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/something/404 -> something/404
[Fri Oct 02 06:00:00.919736 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'something/404'
[Fri Oct 02 06:00:00.919761 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] rewrite 'something/404' -> 'index.php'
[Fri Oct 02 06:00:00.919773 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] add per-dir prefix: index.php -> /srv/http/projectname/webroot/index.php
[Fri Oct 02 06:00:00.919784 2020] [rewrite:trace2] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] strip document_root prefix: /srv/http/projectname/webroot/index.php -> /index.php
[Fri Oct 02 06:00:00.919793 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883c5440/initial] [perdir /srv/http/projectname/webroot/] internal redirect with /index.php [INTERNAL REDIRECT]
[Fri Oct 02 06:00:00.919839 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] strip per-dir prefix: /srv/http/projectname/webroot/index.php -> index.php
[Fri Oct 02 06:00:00.919851 2020] [rewrite:trace3] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] applying pattern '^' to uri 'index.php'
[Fri Oct 02 06:00:00.919868 2020] [rewrite:trace1] [pid 80730] mod_rewrite.c(483): [client 127.0.0.1:33272] 127.0.0.1 - - [projectname.localhost/sid#5579881cec50][rid#5579883b8010/initial/redir#1] [perdir /srv/http/projectname/webroot/] pass through /srv/http/projectname/webroot/index.php
projectname.localhost 127.0.0.1 - - [02/Oct/2020:06:00:00 +0000] "GET /error/404 HTTP/1.1" 404 1131
Alias /error/ "/usr/share/httpd/error/"
但是,对于Ubuntu,该行被注释,因此未启用。在原始Apache文件和Xampp中,默认情况下也会启用错误别名,但在Ubuntu和我的Web服务器上,默认情况下会禁用该别名

由于首先评估配置,URL将执行别名,并且在目标目录中既没有.htaccess文件,也没有名为“something”的文件或目录。因此,结果是一个错误页面。未计算my webroot目录中的.htaccess文件,因为服务器未访问该目录

我从我的Web服务器知道,我无法更改Apache配置本身,只能实现一个.htaccess文件

因此最好的解决方案是仅使用任何默认别名中未使用的目录名。我检查了不同Apache软件包的默认配置文件,以下是一些默认别名:

  • cgi箱
  • cgi酒吧
  • 医生
  • 错误
  • 图标
  • 手册
  • 上传

希望这些信息也能帮助其他人。

我很少遇到如此详细和定义良好的问题++您在项目路径或别名路径中的任何位置都有名为
/error
的文件或目录吗?我很少遇到如此详细和定义良好的问题++您有名为
/error
项目路径或别名路径中的任意位置?