douhui9380 2018-02-09 07:24
浏览 56
已采纳

使用自定义错误页面.htaccess

I want to remove .php file extentions and add custom error page through .htaccess file.

Following is the complete code of my .htaccess file:

RewriteEngine On
#Remove .php file extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*[^/])/?$ $1.php [L]

#Use error500.php file located in the root dir
ErrorDocument 500 /error500 

The first part to remove extension works but second part does not work. It does not use the error500.php file. I have tried adding both with and without .php extention.

Here's the error that I get in the apache error.log

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

What I'm doing wrong?

  • 写回答

1条回答 默认 最新

  • douou0977 2018-02-09 08:15
    关注

    1) Could you try add RewriteBase

    2) Add the extension for error500

    RewriteEngine on 
    RewriteBase /{FOLDER PATH HERE}
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [NC,L]
    
    #Use error500.php file located in the root dir
    ErrorDocument 500 {YOUR DIRECTORY HERE}/error500.php 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?