Forum Moderators: phranque

Message Too Old, No Replies

rewrite mydomain.com/davi to mydomain.com/index.php?id=davi

         

ketari

12:37 pm on May 18, 2005 (gmt 0)



Hi

I want to rewrite [midominio.com...] to [midominio.com...]

.htaccess

RewriteRule ^(.*)$ index.php?id=$1

The result of id=index.php instead id=david

Its Posible? Any Ideas?

However to rewrite [midominio.com...]

RewriteRule ^(.*)/$ index.php?id=$1

The result is ok id=david

jdMorgan

2:13 pm on May 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ketari,

Welcome to WebmasterWorld!

It looks like your Rule is recursive. That is, it will rewrite /david to /index.php?id=david, and then it will rewrite /index.php?id=davis to index.php?id=index.php because there is nothing to stop this from happening. This is because the URL-path "index.php" matches the (.*) pattern.

To back up: Whenever a rewrite completes in .htaccess, control is passed back to httpd.conf and then through any .htaccess file(s) in the new URL-path so that access restrictions or rewrites that apply to the new URL-path can be applied. In this case, this behaviour will make your .htaccess file appear to call itself. Because there is nothing in your rule to prevent a second rewrite, your rule will loop.

Try:


RewriteRule $1 !^index\.php$
RewriteRule ^(.*)/?$ index.php?id=$1

This will explicitly check the requested URL, and will not rewrite if it is equal to "index.php"

Jim