Custom Error 403 Page PHP

拟墨画扇 提交于 2019-11-29 11:38:55

问题


I created a .htaccess inside a directory in which I don't want the files to be directly accessed. It works and fires the default 403 page (Access forbidden!) of the Apache server. How can I create a custom 403 page? Thanks!


回答1:


In your .htaccess file you can specify what document you want as your default 403 error document

ErrorDocument 403 /dir/file.html

Here the directory is relative to the document root.




回答2:


You can do something like the following:


#Rewrite URL's
RewriteEngine On
RewriteRule ^404/?$ errors/404.html [NC]

# Enable Error Documents
# (404,File Not Found) | (403,Forbidden) | (500,Internal Server Error)
ErrorDocument 404 /404
ErrorDocument 403 /404

What this is doing is turning on the RewriteEngine so we can redirect url's nicely, then we are defining using the RewriteRule that /404/ or /404 should redirect to the custom 404 page. I then state that the ErrorDocument 404 and 403 should redirect to the 404 page. I do this for security so, a user does not know whether or not a file exists or if they just don't have access.



来源:https://stackoverflow.com/questions/8703540/custom-error-403-page-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!