使用.htaccess重定向到404错误的php / html文件

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

例如,我想将所有404错误重定向到 404.php。

I want to redirect all 404 errors to "404.php" for example.

我尝试使用 ErrorDocument 404/404。 php 在.htaccess中,但是没有运气,也许我的其他规则不允许这样做,我不确定,因为我在www上找不到此信息。

I've tryed using ErrorDocument 404 /404.php in .htaccess, but without luck, perhaps my other rules are not allowing this somehow, I'm not really sure as I couldn't find this info on www.

如果有人知道如何解决此问题,请大声喊叫:P

If anyone have idea how to solve this, please shout :P

我当前的.htaccess

My current .htaccess

#### pie thingy #### AddType text/x-component .htc #### Rule for Error Page - 404 #### ErrorDocument 404 /404.html #### url rewriting #### Options +FollowSymlinks RewriteEngine on #### REDIRECT IF NO SUB-DOMAIN #### RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)$ [NC] RewriteRule ^(.*)$ www.%1.%2/$1 [R=301,L] #### Remove "www." from any subdomain requests #### RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.precisehire\ [NC] RewriteRule (.*) %1.precisehire/$1 [R=301,L] #### Rules for rewriting from PHP to HTML with fallback #### RewriteCond %{REQUEST_URI} ^/(.*)\.html$ RewriteCond %{DOCUMENT_ROOT}/%1.php -f RewriteRule ^(.*)\.html$ $1.php [nc]

推荐答案

通过放置错误文档的完整URL来解决。

Solved by placing full URL for error document.

示例:

#### Rule for Error Page - 404 #### ErrorDocument 404 www.domain/404.html

更多推荐

使用.htaccess重定向到404错误的php / html文件

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

发布评论

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

>www.elefans.com

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