htaccess的404重定向页面不工作的子目录路径 [英] htaccess 404 page redirect not working for sub directory path
问题描述
的ErrorDocument 404 /404-error.php
这将重定向到404页面完全一样时, www.example.com/about
如果获得约
不存在。但不会重定向到404页,当我访问 www.example.cpm /页/测试
。
其实,有一个名为页面和页面 www.example.cpm /页/测试
不存在。它应该重定向到404页。
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{THE_REQUEST} ^(GET | HEAD)。\ S([^] +)\ PHP [NC]
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S([^。] +)\。PHP [NC]
重写规则^%1 [R,L,NC]
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^%{} REQUEST_FILENAME的.php [L]
的RewriteCond%{HTTP_HOST}!^ WWW \。(。*)$ [NC]
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L]
ErrorDocument的404 /404-error.php
ErrorDocument的500 /404-error.php
您404处理器是找到,但问题是添加的.php
扩展你的重写规则。 的RewriteCond%{} REQUEST_FILENAME -f的.php
返回真 /页/测试
哪怕只是 /page.php
找到。
让你的规则是这样的:
的ErrorDocument 404 /404-error.php
ErrorDocument的500 /404-error.php
选项+的FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 302,L]
的RewriteCond%{THE_REQUEST} ^(?:GET | HEAD)。\ S([^] +)\ PHP [NC]
重写规则^%1 [R,L,NC]
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^([^] +?)/?$ $ 1.PHP [L]
ErrorDocument 404 /404-error.php
It will redirect to 404 page perfectly when access like www.example.com/about
if about
is not exists. But will not redirect to 404 page when I access www.example.cpm/page/test
.
Actually there is page called 'page' and www.example.cpm/page/test
not exists. It should redirect to 404 page.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s([^.]+)\.php [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
ErrorDocument 404 /404-error.php
ErrorDocument 500 /404-error.php
Your 404 handler is find but problem is your rewrite rule for adding .php
extension. RewriteCond %{REQUEST_FILENAME}.php -f
returns true for /page/test
even if just /page.php
is found.
Have your rules like this:
ErrorDocument 404 /404-error.php
ErrorDocument 500 /404-error.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=302,L]
RewriteCond %{THE_REQUEST} ^(?:GET|HEAD)\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+?)/?$ $1.php [L]
这篇关于htaccess的404重定向页面不工作的子目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!