使用.htaccess重定向到404错误的php / html文件 [英] Redirect to a php/html file on 404 error with .htaccess

查看:104
本文介绍了使用.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 ^(.*)$ http://www.%1.%2/$1 [R=301,L]

#### Remove "www." from any subdomain requests ####
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.precisehire\.com [NC]
RewriteRule (.*) http://%1.precisehire.com/$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 http://www.domain.com/404.html

这篇关于使用.htaccess重定向到404错误的php / html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆