Mod Rewrite 500 Error Correction

♀尐吖头ヾ 提交于 2019-12-24 01:28:03

问题


I have a .htaccess file that is using Mod_Rewrite but I am running into a problem if someone puts in junk in the URL it generates a 500 error, and displays all my mod information. I would like to either stop it from generating the 500 error or forward that error to a different page. I have tried.

 Error Document 500 /index.php 

...but it does not work or redirect.

Here is my full .htaccess

 Options -Indexes
 Options +FollowSymlinks

 ErrorDocument 500 /index.php

 RewriteEngine On

 RewriteRule ^BEARS bears.php?page=bears [NC,L]

 RewriteCond %{http_host} ^www.domian.org/login.php [NC]
 RewriteRule ^(.*)$ https://www.domian.org/login.php [R=301,L]

 RewriteCond %{http_host} ^domian.com [NC]
 RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L]

 RewriteCond %{http_host} ^domian.org [NC]
 RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L]

 RewriteCond %{http_host} ^www.domian.com [NC]
 RewriteRule ^(.*)$ http://www.domian.org/$1 [R=301,L]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)/DB/(.+)/page/(.+)$ $1.php?DB=$2&page=$3 [L,QSA]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)/DB/(.+)$ $1.php?DB=$2 [L,QSA]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)/(.+)$ $1.php?page=$2 [L,QSA]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA]

Also does anyone know where the 500 error is being generated from. I know the error folder has the error documents in there, but this error says "Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request" , and I cannot find where this is pulling from.

[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html.php
[Thu Sep 22 11:11:40 2011] [debug] core.c(3071): [client 74.84.118.99] redirected from r->uri = /test.html

Where is this loop happening? Not seeing it.


回答1:


To expand on your answer, it is more specifically this line:

RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA]

which does not check to see if the filename already ends with PHP.

It loops around, adding .php.php.php.php until the max is reached (check apache/logs/error.log) and then just serves the original page, which happens to be present, so it looks like everything's ok.

To fix this, add something like this:

RewriteRule ^(.*)\.php$ - [L]

which stops ([L]) if the address ends with .php.




回答2:


I figured I would put the problem solution here just in case someone comes across the same issue.

My problem code was this snippet...

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)$ $1.php?page=$1 [L,QSA]

Seems that a junk entry will cause this too loop like crazy.



来源:https://stackoverflow.com/questions/7517470/mod-rewrite-500-error-correction

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