I want to block traffic from something that appears to be a bot or some other malicious traffic (haven't quite figured out what it is, but I suppose I don't want it). So far I have been blocking it by IP, however the traffic keeps coming from different locations.
Common for this traffic is that the user agent is PhantomJS, and they all show the following local address (perhaps with some variations):
file:///home/poo_master/price_parse/resource_cache/140578757867264tmp2.html
Is it possible to use .htaccess to block either PhantomJS or anything containing "poo_master/price_parse/resource_cache/"
To block bots/scrapers by useragent OR by requested URL add these rewrite rules to .htaccess:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(PhantomJS|wget|HTTrack|python).*$ [OR]
RewriteCond %{REQUEST_URI} ^.*poo_master/price_parse.*$
RewriteRule . - [F,L]
Update your .htaccess file with below code. Hope it will work.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} ^.*(PhantomJS|wget|HTTrack|python).*$ [OR]
RewriteCond %{REQUEST_URI} ^.*poo_master/price_parse.*$
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Related
using an .htaccess file i'm trying to allow specific referers and my own domain requests to be processed and deny any others, by redirecting anyway.
CanĀ“t get it work using this .htacces...
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://www\.myowndomain\.com(.*) [NC]
RewriteCond %{HTTP_REFERER} !^http://www\.myfrienddomain\.com/subfolder(.*) [NC]
RewriteRule ^(.*)$ http://www.go-out-of-here.com[R=301,L]
RewriteCond %{REQUEST_URI} !^/assets
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
What i try to mean:
If it is not a request from my own domain and it is not a request from my friend's domain...go out of here,
else... passthrough.
Seem to allow from my friends domain but not inner requests, from my own domain.
What's wrong here, friends?? Any ideas?
Thanks in advance!
I am trying to accomplish the following but my code is not working
1) I want to do either non-www to www or www to non-www
2) desktop users should be redirected to example.com/homepage
3) remove or hide /homepage from url
4) redirect mobile users to example.com/m
here is my code, it's not working, too many problems to list, but off the top of my head, I can think of 2 problems that I encountered: "cannot open page because too many redirects occurred" and mobile users are taken to /homepage instead of /m
# remove www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteEngine On
RewriteRule ^$ /homepage [L]
RewriteEngine On
RewriteRule ^$ homepage/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ homepage/$1
RewriteCond %{HTTP_USER_AGENT} ^.*(ip(ad|od|hone)|blackberry|iemobile|android).*$ [NC]
RewriteCond %{REQUEST_URI} !^/m/.*
RewriteRule ^.*$ http://example.com/m [R=301,L]
Please help me, I am so frustrated, what am I supposed to change about this code to get it to work?
Unfortunately im no genious with regex or redirects in htacces but I have gotten similar code to work myself.
It does sound like your code is getting stuck in a redirect loop and the browser is stopping it from continuing.
I know thats not a complete answer but Hopefully that helps you make more sense of the code atleast a little.
Hopefully someone else can chime in otherwise i can dig up the code that is working when im on the computer and hopefully give you a better response.
-Sent from my cell
The www/non-www is fine.
For the homepage stuff, you need to do two things: make sure what you're rewriting into the homepage directory actually exists (otherwise you get a 500 server error) and exclude mobile user agents.
So this stuff:
RewriteEngine On
RewriteRule ^$ /homepage [L]
RewriteEngine On
RewriteRule ^$ homepage/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ homepage/$1
Needs to look like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} !^.*(ip(ad|od|hone)|blackberry|iemobile|android).*$ [NC]
RewriteCond %{DOCUMENT_ROOT}/homepage%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/homepage%{REQUEST_URI} -d [OR]
RewriteRule ^(.*)$ homepage/$1 [L]
I know the basics for writing an .htaccess that handle a maintenance mode page.
I don't want to use a plugin, as I need to replace the whole WP site while in maintenance mode.
I've tried to add additional rules to allows access to WP Back-End, only for specific IPs.
I've tried several attempts and eventually got very close to what I need.
However, I also want the white-listed IP(s) be able to see the front-end site, without being redirected to the maintenance page, but I'm stuck there.
Here's my current .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/images [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin/.* [OR]
RewriteCond %{REQUEST_URI} ^/wp-content/.* [OR]
RewriteRule .+ - [L]
RewriteCond %{REMOTE_ADDR} !^93\.62\.93\.79
RewriteCond %{REQUEST_URI} !^/maintenance-mode\.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance-mode.html [R=302,L]
What I'm supposed to add/change?
Did you found a solution? I don't tested it with WP but this worked for me for another CMS.
Options +FollowSymLinks
RewriteEngine On
# exclude file (otherwise infinity loop)
RewriteCond %{REQUEST_URI} !^/under-construction/maintenance\.php$
# exclude images and css
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]
# If it's not your IP address
RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444$
# Redirect /abc to example.com/abc.
RewriteRule ^(.*)$ http://www.domain.com/under-construction/maintenance.php [R=307,L]
Perhaps it will help you.
I'm trying to mod re-write to a specific sub folder called /checkout this has an SSL certificate attached for https
So I have this in the root folder of my site -
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
# in http: force secure.html to https
RewriteCond %{server_port} !=443
RewriteCond $1 ^([^/]+)$ [NC]
# this kinda works below but is resolving to index2.php and is showing in the url so not really working yet
RewriteRule checkout/([^/]+)\.html$ https://mysite.com/checkout/index2.php [L]
Except that instead of showing something like
https://mysite.com/checkout/index.html
it shows
https://mysite.com/checkout/index2.php
(index2.php is a test url btw)
I've also tried amending the .htaccess in the sub folder to to something like
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{server_port} !=443
RewriteCond $1 ^([^/]+)$ [NC]
RewriteRule ^([^/\.]+)/?$ https://mysite.com/checkout/index2.php [L]
I just want to process
https://mysite.com/checkout/index.html or https://mysite.com/checkout/about-us.html as the same I would in the root like this
https://mysite.com/index.html => https://mysite.com/index.php (and then get the variables etc)
ie
RewriteRule ^/?(catalogue-page)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+) index2.php?friendly_url=$1&catalogue_id=$2&view=catalogue&categoryid=$3&subcategoryid=$4&subjectid=$5&item=$6
I think that https is more complex.
Any pointers/help etc much appreciated
Your RewriteRule seems to indicates that you are trying to take a non-secure url and display a different page via https, this in itself is not possible. Having said that your description doesn't sound like that is the overall aim.
If you wish to force non-secure URLs to be secure, this is fine and it's also fine to want requests for index.html to server index.php. It's not however possible to do this all in one fell swoop.
# first force urls to be secure.
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^checkout/([^/\.]+)/?$ https://mysite.com/%{REQUEST_URI} [R=301,L]
# now rewrite them, so that the requests all get served through the front controller
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^checkout/([^/\.]+)/?$ /checkout/index2.php [L]
at the moment I've got the following code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
What this code does is allow users to go to /pagename instead of /pagename.php
Is there a way to make it so this only works for a specific page because at the moment this code makes this sitewide?
add a new RewriteCond after the two rewriteCond and check if the request is for the specific page.
RewriteCond %{REQUEST_URI} ^/(myPage)/
http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
you can also use the RewriteBase directive.
Example
How does RewriteBase work in .htaccess