本文介绍了使用.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文件
发布评论