htaccess的404重定向页面不工作的子目录路径

编程入门 行业动态 更新时间:2024-10-25 18:36:30
本文介绍了htaccess的404重定向页面不工作的子目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

的ErrorDocument 404 /404-error.php

这将重定向到404页面完全一样时, www.example/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/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 ^(.*)$ 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 ^(.*)$ 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重定向页面不工作的子目录路径

本文发布于:2023-11-01 23:27:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子目录   路径   重定向   页面   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!