404错误没有显示,因为它应该
404 Error not displaying as it should
我手头有一个项目,但遇到了错误。
我有 RewriteRule 将 index.php?view=
重定向到 /
。但是,当我访问本应导致 404 错误的 URL 时,它显示的是主页 (index.php)。
ErrorDocument 404 /pages/errors/error_redirect.php
ErrorDocument 500 /pages/errors/error_redirect.php
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
<FilesMatch "\.tpl$">
Order Allow,Deny
Deny from all
</FilesMatch>
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/errors/404.php [L]
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /pages/errors/500.php [L]
RewriteCond %{REQUEST_FILENAME} !-l
# Rewrite all URLs to non-extension URLs
RewriteRule ^(admin|user)($|/) - [L]
RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view= [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php [L]
我面临的问题是,如果我输入 http://localhost/asdasdads
,浏览器会将我引导至 http://localhost/
而不是 URL 在浏览器中保持不变,但浏览器显示 index.php .它应该显示 404 错误页面。
我相信 RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view= [L]
是这个问题的根源。由于未找到,它正在将 /index.php?view=asdasdads
重定向到 /index.php?view=
。我希望它重定向到 404。
提前致谢。
Aizat,尝试删除不必要的重写条件,然后尝试一下:
设置 404 错误页面的最简单方法是直接在 .htaccess 文件 本身中设置 404 错误消息:
ErrorDocument 404 /404.php
我手头有一个项目,但遇到了错误。
我有 RewriteRule 将 index.php?view=
重定向到 /
。但是,当我访问本应导致 404 错误的 URL 时,它显示的是主页 (index.php)。
ErrorDocument 404 /pages/errors/error_redirect.php
ErrorDocument 500 /pages/errors/error_redirect.php
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
<FilesMatch "\.tpl$">
Order Allow,Deny
Deny from all
</FilesMatch>
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /pages/errors/404.php [L]
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /pages/errors/500.php [L]
RewriteCond %{REQUEST_FILENAME} !-l
# Rewrite all URLs to non-extension URLs
RewriteRule ^(admin|user)($|/) - [L]
RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view= [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ .php [L]
我面临的问题是,如果我输入 http://localhost/asdasdads
,浏览器会将我引导至 http://localhost/
而不是 URL 在浏览器中保持不变,但浏览器显示 index.php .它应该显示 404 错误页面。
我相信 RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view= [L]
是这个问题的根源。由于未找到,它正在将 /index.php?view=asdasdads
重定向到 /index.php?view=
。我希望它重定向到 404。
提前致谢。
Aizat,尝试删除不必要的重写条件,然后尝试一下:
设置 404 错误页面的最简单方法是直接在 .htaccess 文件 本身中设置 404 错误消息:
ErrorDocument 404 /404.php