Web Hosting Talk







View Full Version : mod_rewrite problems


Jamza
01-11-2010, 07:31 PM
I have a simple htaccess file (below) that should rewrite the URL from something like page http://127.0.0.1/urlhandler.php?page=test to http://127.0.0.1/test/.

RewriteEngine On

RewriteRule ^([^/]*)$ /urlhandler.php?page=$1 [L]

But everytime I try to access something it gives me a 500 internal server error.

I looked in the server log and it outputs this entry:

[Mon Jan 11 23:24:43 2010] [error] [client 127.0.0.1] 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.

I can't see what the error really is, does anybody know how I can fix this error?

foobic
01-11-2010, 07:39 PM
Your rewritten url still matches the rewrite rule, so it gets rewritten again, and again, etc. until you hit the redirect limit.

Add a RewriteCond before your rule that excludes urlhandler.php.

Jamza
01-11-2010, 08:24 PM
Thanks, that had fixed it. :D

Never realised that it would include the url handler.

Jamza
01-12-2010, 10:30 AM
Ive run into another problem.

Yes thanks to foobic I did get HTaccess to push the url to my url handling script. But the problem is, its only pushing one thing. http://127.0.0.1/foo would work, but http://127.0.0.1/foo/bar/ wouldn't (gives a 404).

This is my htaccess file at the moment:
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]*)$ /dlm_handler.php?page=$1 [L]

Does anyone know how I can change this to send the whole string after the domain (http://127.0.0.1/foo/bar/) to my script? Thank you.

mattle
01-12-2010, 11:51 AM
Ive run into another problem.

Yes thanks to foobic I did get HTaccess to push the url to my url handling script. But the problem is, its only pushing one thing. http://127.0.0.1/foo would work, but http://127.0.0.1/foo/bar/ wouldn't (gives a 404).

This is my htaccess file at the moment:
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^/]*)$ /dlm_handler.php?page=$1 [L]Does anyone know how I can change this to send the whole string after the domain (http://127.0.0.1/foo/bar/) to my script? Thank you.

Your regular expression dictates that the string must match the character set "not forward slash" from beginning to end. The string "foo/bar/" has forward slashes and therefore does not meet your condition. If you want to send everything after http://127.0.0.1/ (rewrite rules start matching after the domain's trailing slash) then this regex should be all you need: ^(.*)$

Jamza
01-12-2010, 03:35 PM
Thats solved it. Now its working completely as I want it. Thank you so much :D