2016-07-29 44 views
1

我手边有一个项目,但遇到一个错误。404错误没有显示,因为它应该

我有RewriteRule将index.php?view=$1重定向到/。但是,当我访问一个应该导致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=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*)$ $1.php [L] 

我面临的问题是,如果我进入http://localhost/asdasdads,浏览器导致我http://localhost/而不是用在浏览器网址不变,但浏览器中显示的index.php。它应该显示一个404错误页面。我认为RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view=$1 [L]是这个问题的根源。由于未找到/index.php?view=asdasdads/index.php?view=,因此它正在重定向。我想它重定向到404而不是。

预先感谢您。

回答

0

Aizat,请尝试删除不必要的重写条件,并就这是一个尝试:

最简单的方法来设置一个404错误页面是由.htaccess文件直接设置一个404错误消息本身:

的ErrorDocument 404 /404.php

相关问题