Thomas Ahle
Thomas Ahle

Reputation: 31614

Weird ModRewrite recursion

I have written this simple .htaccess file on my localhost for testing:

RewriteEngine on
RewriteRule ^(.+)$ $1a    
RewriteRule ^(.+)$ $1b 

Now requesting http://localhost/test/x, I get the error Forbidden on /test/xa/xba/xa/xbba/xa/xba/xa/xbbba/xa/xba/xa/xbba/xa/xba/xa/xbbbba/...

I don't understand why this happens, since I don't use the [N] flag, or anything else, that should cause mod_rewrite to recurse. Also, even if it did recurse, I would expect /test/xabababababababababa... not that nearly tree looking pattern above.

Can anyone tell me what's going on?

Upvotes: 0

Views: 1228

Answers (1)

LazyOne
LazyOne

Reputation: 165228

Because that is how mod_rewrite works -- after rewriting happens it goes to next iteration (when exactly -- it depends on rewrite flags and other "moments").

If you do not build your rule in a correct manner you will have rewrite loop, which Apache has to forcibly stop at some point.

Useful link to read: RewriteRule Last [L] flag not working?

Upvotes: 1

Related Questions