Haru
Haru

Reputation: 1381

Mod Rewrite 500 Error Correction

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.

Upvotes: 2

Views: 1233

Answers (2)

Ben
Ben

Reputation: 57287

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.

Upvotes: 1

Haru
Haru

Reputation: 1381

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.

Upvotes: 1

Related Questions