views:

23

answers:

1

I use the following rule to redirect pretty urls from http://hostname.co.za/geoip/123.12.123.34 to http://hostname.co.za/geoip/index.py?ip=123.12.123.34

.htaccess in /geoip

RewriteEngine on
RewriteRule ^(.*\..*\..*\..*)$ /geoip/index.py?ip=$1

This works fine to match only ip's, but when I try this, it gives a 500 server error:

RewriteEngine on
RewriteRule ^(.*\..*)$ /geoip/index.py?ip=$1

I want to match not only ip's, but hostnames with at least one fullstop as well. I have no idea why this shouldn't work...

+2  A: 

The problem with the second pattern is that it also matches index.py and thus yields an infinite recursion. You can exclude that by using a RewriteCond:

RewriteCond $1 !=index.py
RewriteRule ^(.*\..*)$ /geoip/index.py?ip=$1

Furthermore, you should use a more specific pattern than .* like [^/.]+, so:

RewriteCond $1 !=index.py
RewriteRule ^([^/.]+\.[^/.]+)$ /geoip/index.py?ip=$1
RewriteRule ^([^/.]+\.[^/.]+\.[^/.]+\.[^/.]+)$ /geoip/index.py?ip=$1
Gumbo
Thanks, the index.py was the problem - sorted with the RewriteCond rule.
bluegray
@bluegray: To show your appreciation, please accept Gumbo's answer (click the checkmark next to it).
Tim Pietzcker