.htaccess无法重定向到错误页面

编程入门 行业动态 更新时间:2024-10-26 22:21:47
本文介绍了.htaccess无法重定向到错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了 .htaccess 文件来删除网站的规范问题。 这是代码:

I'd created .htaccess file to remove canonical issue with my site. Here's the code:

<Files ~ "^\.(htaccess|htpasswd)$"> deny from all </Files> ErrorDocument 404 www.reddyclasses/error.php RewriteEngine on RewriteCond %{HTTP_HOST} ^(reddyclasses\)(:80)? [NC] RewriteRule ^(.*) www.reddyclasses/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1 [L,QSA] RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC] RewriteRule ^ /%1 [R=301,L] DirectoryIndex index.php index.html order deny,allow

此代码正确吗?另外,如果我输入了错误的URL,例如 reddyclasses/err ,则我的网站不会重定向到错误页面。为什么?

Is this code is correct? Also, my site is not redirecting to error page if I do enter a wrong url like reddyclasses/err. Why?

推荐答案

它不会重定向,因为您将所有流量都重定向到index.php,所以 reddyclasses/err 确实存在。在这种情况下,您需要从PHP本身触发404错误。

it doesn't redirect because you redirect all traffic to index.php so reddyclasses/err does exist. You need to trigger 404 error from PHP itself in this case..

更多推荐

.htaccess无法重定向到错误页面

本文发布于:2023-10-31 16:44:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546677.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   错误   页面   htaccess

发布评论

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

>www.elefans.com

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