Hello I am receiving visit from seekport crawler (just a few but I want to avoid them at all).
The rule now is:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} OnalyticaBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "=Re-re Studio (+http://vip0.ru/)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "=Mozilla/5.0 (compatible; Seekport Crawler; http://seekport.com/" [NC]
RewriteRule ^ - [F]
All this one works, but there is another seekport crawler user agent with this string: "'Mozilla/5.0 (compatible; Seekport Crawler; http://seekport.com/'" (the same but using ' and the begging and at the end).
Using RewriteCond %{HTTP_USER_AGENT} "='Mozilla/5.0 (compatible; Seekport Crawler; http://seekport.com/'" is not working, the ones with this "new" user agent are not blocked.
May I have to use any character like "" anywhere?. Maybe the problem is the char ' at the end and the beggining??
Many thanks
The easiest way is to use:
RewriteCond %{HTTP_USER_AGENT} Seekport [NC]
To block all Seekport crawlers…
Related
I'm trying to block the access to this user agent who's visiting me: Mozilla/5.0 (compatible; Seekport Crawler; http://seekport.com/ (with no ) at the end, its not a fault).
I have tried this one (with two more agents)
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} OnalyticaBot [NC, OR]
RewriteCond %{HTTP_USER_AGENT} Re-re Studio (+http://vip0.ru/) [NC, OR]
RewriteCond %{HTTP_USER_AGENT} Mozilla/5.0 (compatible; Seekport Crawler; http://seekport.com/ [NC]
RewriteRule .* - [F,L]
I have tried a couple more with this sintax (using entire string and using only "Seekport") but still seeing the agent user asking for in the log
RewriteCond %{HTTP_USER_AGENT} ^.(user_agent1|user_agent2).$ [NC]
Could you help me?
RewriteCond %{HTTP_USER_AGENT} Re-re Studio (+http://vip0.ru/) [NC, OR]
By default, the 2nd argument to the RewriteCond directive is a regular expression (regex), so any meta characters (eg. + and .) need to be properly escaped. But importantly, spaces are delimiters in Apache config files so these also need to be escaped, otherwise, the directive will be wholly invalid. On Apache, the above will result in a fatal error (500 Internal Server Error) due to "bad flag delimiters". On LiteSpeed, it will simply fail silently.
Spaces can be "escaped" by either:
Precede the space with a backslash. eg. \ in hello\ world
Or, use a \s shorthand character class to represent any white-space character. eg. hello\sworld.
Or, enclose the entire argument in double-quotes. eg. "hello world".
[NC, OR] - However, there should be no spaces in the flag delimiters argument. This should be [NC,OR] (no space).
So, the above could be written like this:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} OnalyticaBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "Re-re Studio (\+http://vip0\.ru/)" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "^Mozilla/5\.0 (compatible; Seekport Crawler; http://seekport\.com/$" [NC]
RewriteRule ^ - [F]
The regex .* in the RewriteRule pattern can be simplified to just ^ (which is more efficient) and the L flag is not required when using F - it is implied.
If you want to match an entire user-agent string then you can use the = (lexicographical string comparison for equality) prefix operator (together with double-quotes) on the CondPattern to test for an exact match.
For example:
RewriteCond %{HTTP_USER_AGENT} "=This is the exact user-agent I want to block"
RewriteRule ^ - [F]
In the above example, the string This is the ... block is an ordinary string, not a regex.
I would like to know if there is a way to block all user-agents except the one that contains the word "chrome" using .htaccess
I used something like this, but this works unfortunately only if the exact name is given..
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !Lynx/2\.8\.8dev\.12 [NC]
RewriteRule ^ - [F,L]
You can just use:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !chrome [NC]
RewriteRule ^ - [F]
I've been looking everywhere for an answer to my question but can't seem to find one. I'm trying to set up a redirect in my .htaccess file to the mobile version of my website (which is set up as a subdomain) for every type of mobile device imaginable EXCEPT the iPad and Android tablet. The closest things I've seen are this and this, but neither one helped me.
I found code that sort of works for me (in the sense that it definitely redirects to the mobile version of my site when using an Android phone), but it presents at least two problems: 1) It includes a redirect for users who are on iPads, which I don't want, and 2) It throws an Internal Server Error when viewed on non-mobile browsers (I think the ".au" extension used in the code is because the person who came up with the code is in Australia -- and I'm not, so I deleted that ".au" when entering my subdomain -- but I doubt this has anything to do with the issue):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^m.website.com.au$
RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ipad [NC]
RewriteRule ^(.*)$ http://m.website.com.au/$1 [R=302,L]
RewriteCond %{HTTP_HOST} !^m.website.com.au$
RewriteCond %{HTTP_USER_AGENT} android [NC]
RewriteCond %{HTTP_USER_AGENT} !mobile [NC]
RewriteRule ^(.*)$ http://m.website.com.au/$1 [R=302,L]
RewriteCond %{HTTP_HOST} !^m.website.com.au$
RewriteCond %{REQUEST_URI} !^/serverfolder/(.*)
RewriteRule (.*) /serverfolder/$1 [L]
</IfModule>
Can anyone please tell me what I'm doing wrong? Thanks in advance for your help.
Ok, I figured it out. This link really helped. I hope this helps anyone who may be struggling like I did.
at the end of my .htaccess i redirect all url that i consider faulty.
this works perfect but i need an exception for my own pc
for my firefox browser i want the server to react as every other request
for my chrome browsers i want full access to all files on the server
i do it this way and it works:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/retpic.php
RewriteCond %{REQUEST_URI} !^/pcs/.*$
RewriteCond %{REMOTE_HOST} ^11\.11\.1\.11$
RewriteCond %{HTTP_USER_AGENT} Firefox
RewriteRule . index.php [L]
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/retpic.php
RewriteCond %{REQUEST_URI} !^/pcs/.*$
RewriteCond %{REMOTE_HOST} !^11\.11\.11\.11$
RewriteRule . index.php [L]
but i end up doubling the whole code... is there a more elegant solution like combining the following with an AND statement? (i found something about an OR statement but not about AND)
RewriteCond %{REMOTE_HOST} ^11\.11\.1\.11$
RewriteCond %{HTTP_USER_AGENT} Firefox
edit: added more explanation on how the code works:
RewriteCond %{REMOTE_HOST} !^11\.11\.11\.11$
this is from the second part it excludes my ip from this rule so i can access all files on the server, this is important since i want to be able to access my cms
RewriteCond %{REMOTE_HOST} ^11\.11\.1\.11$
RewriteCond %{HTTP_USER_AGENT} Firefox
this parts includes my firefox browser when i am home so i can see if the website works with all restrictions in place. why do i have this rule: i was working on my site and restructuring some parts and it kept on working for me but when i was at a friends place i noticed it did not so i needed something to be able to check this at home.
You nee do apply little bit of boolean algebra to combine these rules into one.
Here is you can do it for you:
RewriteCond %{REMOTE_ADDR} !=11.11.2.11 [OR]
RewriteCond %{HTTP_USER_AGENT} Firefox
RewriteRule !(index\.php|retpic\.php|pcs/) index.php [L,NC]
RewriteRule ^(.*)\.php$ ^(.*)\.php$?m=0 [R=301,L]
I want all inside pages to be rewritten to ?m=0 coming from SITEDOTCOM?m=0
So basically if someone lands comes to the full site using the trailing ? i want all the links to be ?m=0
??
REASON: Mobile redirect Full Site button works once. Does not work if user clicks on something. returns to mobile site.
my code looks like this
RewriteEngine on
RewriteBase /
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.Site.com%{REQUEST_URI} [R,L]
Tried top code return infinite loop.? thoughts?
This line here:
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)
should probably be checking the query string instead as well:
RewriteCond %{QUERY_STRING} !(^|&)mobile=0(&|$)
Because the cookie isn't sent to the browser until the server responds, by that time the redirect is already made. The two CO lines creates a cookie to be sent to the browser, and immediately you redirect them to mobile before there's a response.
How about something like this? Change the redirect rule to:
RewriteCond %{HTTP:Cookie} mobile=1(;|$)
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^ http://m.Site.com%{REQUEST_URI}?mobile=1 [R,L]
RewriteCond %{HTTP:Cookie} \mobile=0(;|$)
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^ http://Site.com%{REQUEST_URI}?mobile=0 [R,L]