loops?! apache crashes!

Discuss practical ways rearrange URLs using mod_rewrite.

loops?! apache crashes!

Postby expream » Fri Feb 20, 2009 5:49 pm

Hello!

I have a little problem with mod_rewrite ... here is my .htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^xxx/xaage2.html$ index.php?q=sobrid_ak.html&page=2 [N,QSA]
RewriteRule ^([a-z0-9_\.]*)$ index.php?q=$1 [N,QSA]
#RewriteRule ^([A-Za-z0-9_\.]*)/iveikals/([A-Za-z0-9_]*)$ index.php?q=$1&object_id=$2 [L,QSA]
RewriteRule ^iveikals/precugrozs.html$ index.php?q=2&shoppingcart [N,QSA]
RewriteRule ^iveikals/shoppingcart.html$ index.php?q=2&shoppingcart [N,QSA]
RewriteRule ^iveikals/([a-z0-9_\.]*).html$ index.php?q=2&object_id=$1 [N,QSA]
RewriteRule ^iveikals/([a-z0-9_\.]*)/page([0-9]+).html$ index.php?q=2&object_id=$1&page=$2 [N,QSA]
RewriteRule ^iveikals/([a-z0-9_\.]*)/page([0-9]+)/filter([0-9]+).html$ index.php?q=2&object_id=$1&page=$2&src=$3 [N,QSA]
RewriteRule ^iveikals/([a-z0-9_\.\"\-]*)/([a-zA-Z0-9_\.\"\-]*).html$ index.php?q=2&object_id=$1&product_id=$2 [L,QSA]
#RewriteRule ^iveikals/([A-Za-z0-9_]+).html?$ index.php?id=2&object_id=$1 [L]

when I enable this one: RewriteRule ^xxx/xaage2.html$ index.php?q=sobrid_ak.html&page=2 [N,QSA] - it is 3rd line and goto http://mydomain.com/ - apache start eating ram ... then start eat swap and.. and then server became unavailable.... apache CPU usage 100% , mem usage about 100% too ..

I have tried to put in global httpd.conf:

LimitInternalRecursion 5 5

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteOptions inherit

but this doesn't help. So as I understand there is endless loooooop? which kills server?

The question is.. how to prevent such server crashes?! Because I share server with other clients and when someone have such error in mod_rewrite rules... it will be problem for all clients. Is it possible to set some limits???

CentOS 5, Apache 2.2.3

Thanks! Waiting for help!
expream
 
Posts: 3
Joined: Fri Feb 20, 2009 5:41 pm

Postby richardk » Sat Feb 21, 2009 1:42 pm

when I enable this one: RewriteRule ^xxx/xaage2.html$ index.php?q=sobrid_ak.html&page=2 [N,QSA] - it is 3rd line

Why are you using the N flag?
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule wrote:'next|N' (next round)
Re-run the rewriting process (starting again with the first rewriting rule). This time, the URL to match is no longer the original URL, but rather the URL returned by the last rewriting rule. This corresponds to the Perl next command or the continue command in C. Use this flag to restart the rewriting process - to immediately go to the top of the loop. Be careful not to create an infinite loop!


I have tried to put in global httpd.conf:

LimitInternalRecursion 5 5

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteOptions inherit

but this doesn't help.

RewriteOptions Inherit has to go in the .htaccess file for the rules to be inherited.

The loop is almost certainly caused by the conditions
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

not being before
Code: Select all
RewriteRule ^([a-z0-9_\.]*)$ index.php?q=$1 [N,QSA]


Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^xxx/xaage2\.html$ /index.php?q=sobrid_ak.html&page=2 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z0-9_\.]+)$                                            /index.php?q=$1                            [QSA,L]

#RewriteRule ^([a-zA-Z0-9_\.]+)/iveikals/([a-zA-Z0-9_]+)$                /index.php?q=$1&object_id=$2               [QSA,L]
RewriteRule ^iveikals/(precugrozs|shoppingcart)\.html$                  /index.php?q=2&shoppingcart                [QSA,L]
RewriteRule ^iveikals/([a-z0-9_\.]+)\.html$                             /index.php?q=2&object_id=$1                [QSA,L]
RewriteRule ^iveikals/([a-z0-9_\.]+)/page([0-9]+)\.html$                /index.php?q=2&object_id=$1&page=$2        [QSA,L]
RewriteRule ^iveikals/([a-z0-9_\.]+)/page([0-9]+)/filter([0-9]+)\.html$ /index.php?q=2&object_id=$1&page=$2&src=$3 [QSA,L]
RewriteRule ^iveikals/([-a-z0-9_\."]+)/([-a-zA-Z0-9_\."]+)\.html$       /index.php?q=2&object_id=$1&product_id=$2  [QSA,L]
#RewriteRule ^iveikals/([a-zA-Z0-9_]+)\.html?$                           /index.php?id=2&object_id=$1               [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby expream » Sun Feb 22, 2009 6:57 am

Ok thank for help! I will repost this message to client.

But I , as server admin, interested in "hot to prevent" this kind of crashes?? Ok, now he knows, he will correct his rules and it will be working, but what if other user will have the same error? The server will be down again. So ... if you know .. how to set limit or how to prevent apache from being crashed.. that is the question...
expream
 
Posts: 3
Joined: Fri Feb 20, 2009 5:41 pm

Postby richardk » Sun Feb 22, 2009 12:48 pm

Code: Select all
LimitInternalRecursion 5 5

should work (according to the docs) in the httpd.conf file, i don't know why it didn't. If you have <VirtualHost>s you could try repeating it in them.

Or you can try
Code: Select all
Options +FollowSymlinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

in the httpd.conf file (and/or <VirtualHost>s) and
Code: Select all
RewriteOptions Inherit

in the .htaccess files.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby expream » Sun Feb 22, 2009 1:00 pm

ok.. will try... and then will inform you... if it helped or not...
expream
 
Posts: 3
Joined: Fri Feb 20, 2009 5:41 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 23 guests

cron