0

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?

Thomas Ahle
  • 30,774
  • 21
  • 92
  • 114
  • Also weird: Adding `[L]` to the first line gives an Internal Server Error, while adding it to the second line changes nothing. – Thomas Ahle Aug 16 '11 at 08:23

1 Answers1

1

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?

Community
  • 1
  • 1
LazyOne
  • 158,824
  • 45
  • 388
  • 391