How should I add a global htaccess rules?

qiuai

Verified User
Joined
May 10, 2010
Messages
23
I want add a global htaccess rules like this:

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^ApacheBench
RewriteRule ^(.*)$ http://people.com.cn/

but when i added it on /etc/httpd/conf/httpd.conf .it won't work.
it works normal on other server.

This makes me very troubled.
what i can do?
thanks.
 
Hello,

Does it work as you expect if you add it into .htaccess of one of your web-sites on that affected server?
 
Of course it work.

And it work normal on other server without directadmin.

And,I want ask a question...

In china,a soft name "wa jue ji."The log of apache like this..What i can do?thanks.

119.137.94.234 - - [25/Apr/2012:07:15:33 +0800] "GET /111.rar HTTP/1.1" 404 551 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:33 +0800] "GET /bstn888.rar HTTP/1.1" 404 555 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:33 +0800] "GET /888.rar HTTP/1.1" 404 551 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:34 +0800] "GET /888.rar HTTP/1.1" 404 551 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:34 +0800] "GET /image/iss.php HTTP/1.1" 404 557 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:34 +0800] "GET /plus/neeciss.php HTTP/1.1" 404 560 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:34 +0800] "GET /uavrdb.rar HTTP/1.1" 404 554 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:34 +0800] "GET /db.rar HTTP/1.1" 404 550 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:34 +0800] "GET /db.rar HTTP/1.1" 404 550 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:35 +0800] "GET /ithwtest.rar HTTP/1.1" 404 556 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:35 +0800] "GET /test.rar HTTP/1.1" 404 552 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:35 +0800] "GET /plus/iss.php HTTP/1.1" 404 556 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:35 +0800] "GET /plus/iss.php HTTP/1.1" 404 556 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:35 +0800] "GET /admin/hrtcuc.php HTTP/1.1" 404 560 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:35 +0800] "GET /test.rar HTTP/1.1" 404 552 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:35 +0800] "GET /admin/uc.php HTTP/1.1" 404 556 "-" "Mozilla/4.0"
222.186.18.43 - - [25/Apr/2012:07:15:35 +0800] "GET /admin/uc.php HTTP/1.1" 404 556 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:35 +0800] "GET /amwqdata.rar HTTP/1.1" 404 556 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:35 +0800] "GET /data.rar HTTP/1.1" 404 552 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:36 +0800] "GET /data.rar HTTP/1.1" 404 552 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:36 +0800] "GET /jabzdb/db.rar HTTP/1.1" 404 557 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:36 +0800] "GET /db/db.rar HTTP/1.1" 404 553 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:36 +0800] "GET /db/db.rar HTTP/1.1" 404 553 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:37 +0800] "GET /arerwebroot.rar HTTP/1.1" 404 559 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:37 +0800] "GET /webroot.rar HTTP/1.1" 404 555 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:37 +0800] "GET /webroot.rar HTTP/1.1" 404 555 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:37 +0800] "GET /ptly0.rar HTTP/1.1" 404 553 "-" "Mozilla/4.0"
119.137.94.234 - - [25/Apr/2012:07:15:37 +0800] "GET /0.rar HTTP/1.1" 404 549 "-" "Mozilla/4.0"
 
Last edited:
but when i added it on /etc/httpd/conf/httpd.conf .it won't work.

Where exactly do you add it? I guess you need to put it into <Directory directory-path> ... </Directory> or <Location ...> ... </Location> section.
 
I guess you need to put it into <Directory directory-path> ... </Directory> or <Location ...> ... </Location> section.
 
I want it work with all the user...

and on another server,i put it into the last of httpd.conf .it work.
 
I try this.but it still don't work.

<Directory /home/*>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^ApacheBench
RewriteRule ^(.*)$ http://people.com.cn/
</Directory>
 
Code:
<Location />
# Ban ab & wget
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^ApacheBench
RewriteRule ^(.*)$ [url]http://people.com.cn/[/url]
</Location>

I add it into /etc/httpd/conf/extra/httpd-includes.conf,and it work now.
But the normal htaccess rules don't work.
 
Last edited:
But the normal htaccess rules don't work.
I'm not sure what you mean by this, since the rules in your post #10 match exactly the rules in your post #1, except for the location context.

I don't see anywhere in this thread which version of apache you're running, and when I try your site, calling up an error, you don't show the apache version in your error message, so I don't know the version you're running. I looked up the documentation for mod_rewrite for Apache 2.2 (apache.org) and it indicates it should work in the serverwide context but that it requires the full path. The /etc/httpd/conf/extra/httpd-includes.conf file is an included file and is therefore part of httpd.conf. So why doesn't it work? I'm not sure; it may require the location context when used server wide. For more information, feel free to find the documentation I found and the additional documentation in a link on that page I didn't take the time to read. There does not appear to be a Chinese language version of the documentation.

Jeff
 
When i use that rules on other server without directadmin(Only install apapche ,php ,mysql).I put it into the last of httpd.conf,It works normal.but when i put it into the directadmin server,the last of httpd.conf,it don't work anymore.
and when i put it into httpd-include.conf.it still don't work.
 
I guess the order of included Apache files might matter... Note I did not tried it, so I can't tell for sure. But Jeff is right, I also met the statement, that mod_rewrite rules should work in the serverwide context.

The reason I could think of is that somewhere you've already got mod_rewrite rules in Location or Directory section, and to redefine them you should also use the same Location or Directory section.
 
When i use it on my server with directadmin.it don't work.but it work normal with server without directadmin.

I must use it in public server.but i don't have test server with directadmin.That's why i ask this question here.

China is a Magical place.Many people use software to scan your server,They want find your backup file.Like www.zip .But it make my server running hard.so i want Shielded these scan.

I will temporarily stop working on this,And make program to make my billing system can create account Automatic.

zEitEr's ,jeff .Thanks very much.
 
Back
Top