Which rule is right?

Hi.
I setup some rules in nginx.conf, but I don’t known which is right, 1 or
2? Please help me, Thanks.

1,
location ~* ..(jpg|jpeg|gif|png|js|ini|css|xml|ico|swf|bmp|html|htm)$
{
if ($http_user_agent ~
baidu|spider {
rewrite ^/ http://www.mydomain.com/robots.txt;
}
if ($http_referer ~* baidu|spider {
rewrite ^/ http://www.mydomain.com/robots.txt;
}
valid_referers none blocked *.mydomain.com;
if ($invalid_referer) {
rewrite ^/ http://www.mydomain.com/error.html;
access_log on;
}
expires 30d;
access_log off;
}

OR

2,
location ~* ..(jpg|jpeg|gif|png|js|ini|css|xml|ico|swf|bmp|html|htm)$
{
if ($http_user_agent ~
baidu|spider {
rewrite ^/ http://www.mydomain.com/robots.txt;
}
if ($http_referer ~* baidu|spider {
rewrite ^/ http://www.mydomain.com/robots.txt;
}
expires 30d;
access_log off;
}
location ~* .*.(jpg|jpeg|gif|png|js|ini|css|xml|ico|swf|bmp|html|htm)$
{
valid_referers none blocked *.mydomain.com;
if ($invalid_referer) {
rewrite ^/ http://www.mydomain.com/error.html;
}
}

Posted at Nginx Forum:

if ($http_user_agent ~* baidu|spider

sorry, it need to add “)”.

It’s if ($http_user_agent ~* baidu|spider)

Posted at Nginx Forum:

Which is right? or are all wrong?

Can anyone help me?

Posted at Nginx Forum: