gpt4 book ai didi

Apache "File not found."而不是 404. 错误文档

转载 作者:行者123 更新时间:2023-12-04 17:20:17 26 4
gpt4 key购买 nike

我想设置一个自定义的 404 错误文档,但是我遇到了问题!

首先,我的 .htaccess 中有两个 RewriteRules:

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /$2/$3.php?lang=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/?$ /$2/$3/$4.php?lang=$1 [L]

所以我的 URL 看起来像:/de-de/page/other/stuff 和 opend/page/other/stuff.php?lang=de-de

现在是时候设置我自己的错误文档了:错误文档 404/404.php

如果“/de-de/page/other/”中有错误,例如“/de-de/wrong/page/”,我就成功获取了错误文档。但是,如果 php 文件名有误(例如“wrong-stuff”而不是“stuff”),我只会收到消息“找不到文件”。但不是我的错误文档。

怎么了?我该怎么做才能修复它?

感谢您的帮助!

AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /var/www/vhosts/<domain>/development/tests/demo.<domain>/.htpasswd
Require valid-user

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,QSA]
</IfModule>



RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /$2/$3.php?lang=$1 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/?$ /$2/$3/$4.php?lang=$1 [L]

ErrorDocument 404 /404.php

Apache 错误日志:

[404] GET /de-de/support/support/fdfssdf HTTP/1.0
AH01071: Got error 'Primary script unknown\n'

最佳答案

使用RewriteCond检查php文件是否存在:

RewriteCond %{REQUEST_URI} ^/([^/.]+)/([^/.]+)/([^/.]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%2/%3.php -f
RewriteRule ^ /%2/%3.php?lang=%1 [L]

RewriteCond %{REQUEST_URI} ^/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/?$
RewriteCond %{DOCUMENT_ROOT}/%2/%3/%4.php -f
RewriteRule ^ /%2/%3/%4.php?lang=%1 [L]

关于Apache "File not found."而不是 404. 错误文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37898054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com