How can i ban requests form pingdomtools?
Their hostnames looks like that:
s464.pingdom.com
So how can i ban all hostnames ending with
pingdom.com
?
You could use a rewrite rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://([^.]+\.)*tumblr\.com [NC]
RewriteRule .* - [F]
</IfModule>
http://davidwalsh.name/block-domain
Note: This blocks based on referer, which can be spoofed or left out entirely.
Update: On servers that do reverse dns you can try:
deny from .pingdom.com
https://httpd.apache.org/docs/2.0/mod/mod_access.html#allow
RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} somesite\.com [NC,OR]
RewriteRule .* - [F]
Well since it's not easy to ban the hostname i just banned the User agent:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Pingdom.com
RewriteRule ^(.*)$ http://go.away/
Works fine.
Related
I have some old URL's that I want to fix because of a forum migration.
The old URL's look like:
http://www.example.com/forum/topic.asp?TOPIC_ID=666
I want to redirect them to:
http://www.example.com/forum/missions/666
My approach is this, but I'm scratching my head, because it doesn't work at all:
RewriteCond %{QUERY_STRING} ^TOPIC_ID=(.*)$ [NC]
RewriteRule ^/forum$ /forum/missions/%1 [NC,L,R=301]
Assuming there is no .htaccess in `/forum/, you can use this first rule in your root .htaccess:
RewriteCond %{QUERY_STRING} ^TOPIC_ID=([^&]+) [NC]
RewriteRule ^forum/topic\.asp$ /forum/missions/%1? [NC,L,R=302]
If there is a .htaccess in /forum/, then you can use this first rule in your /forum/.htaccess:
RewriteCond %{QUERY_STRING} ^TOPIC_ID=([^&]+) [NC]
RewriteRule ^topic\.asp$ /forum/missions/%1? [NC,L,R=302]
I'd suggest this, but cannot really try from here :)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^forum/topic.asp\?TOPIC_ID=([0-9]+)$ forum/missions/$1 [L]
</IfModule>
This seems simple enough, but the documentation and search results on mod_rewrite are a bit lacking. In the interest of saving time, can someone explain to me the best way to direct my traffic?
If the url is /show/checkout I want https://servername.com/show/checkout. If the url is anything else, I want it to go to http://servername.com/show/whatever.
I've got mod_rewrite enabled. I am able to send all traffic to https, but I haven't succesfully filtered out /show/checkout traffic. This doesn't work because there is some insecure images/scripts that are causing security warnings in some browsers.
Thanks!
Current .htaccess that sends all traffic to https:
Order allow,deny
Allow from all
Deny from 65.208.151.
Options -Indexes
AddHandler fastcgi-script .fcgi
AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1
DirectoryIndex index.cgi
RewriteEngine on
RewriteRule ^/(.*)$ http://myserver.com/$1 [R,L]
RewriteRule ^show/product/(.*)$ ?content=product;title=$1 [QSA,L]
RewriteRule ^show/(.*)/(.*)$ ?content=$1;nth=$2 [QSA,L]
RewriteRule ^show/(.*)$ ?content=$1 [QSA,L]
RewriteRule ^place/order$ ?email=order [QSA,L]
RewriteRule .htm$ /
This rule:
RewriteRule ^/(.*)$ http://myserver.com/$1 [R,L]
doesn't do anything, since URI's used to match on won't start with a /. Not just that, this rule is simply a redirect loop.
Remove that and try adding this:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_REFERER} !show/checkout
RewriteCond $1 !^show/checkout
RewriteRule ^(.*)$ http://servname.com/$1 [L]
RewriteCond %{HTTPS} off
RewriteCond $1 ^show/checkout
RewriteRule ^(.*)$ https://servname.com/$1 [L]
I have several urls on a Joomla site which have been indexed and I need to 301 redirect them into some new pages. The old URL is formed like this:
http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=20
I want it to go to:
http://www.mydomain.com/en/family-members/family-disease
I tried using:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^/en/wfmenuconfig/family/family-disease/177-category-english$ http://www.www.mydoamin.com/en/family-members/family-disease%1 [R=301,L]
I've tried several answers on here but nothing seems to be working.
htaccess 301 redirect dynamic url
and
301 Redirecting URLs based on GET variables in .htaccess
Any ideas what I should try next? (I've tried a normal redirect 301)
You've almost got it. You need to remove the leading slash from your rule's pattern because it's removed from the URI when applying rules from an htaccess file:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease%1? [R=301,L]
You also don't need the http://www.www.mydoamin.com bit (2 sets of www). At the end of your target, you have family-disease%1, which means if start=20 then the end of your URL will look like: family-disease20. Is that right?
The new URL doesn't have the query string in it, so it is just stripping of the last URL path part. If you want it hardcoded
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease? [R,L]
or a little bit more flexible
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/.+$ /en/family-members/family-disease? [R,L]
or if you just want to keep two levels after en/wfmenuconfig
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/(.+?/.+?)/ /en/$1? [R,L]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
If you just want to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease, then you must try these directives:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease [R=301,L]
But if that's not what you want, but to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease$var then you could check this one:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease%1 [R=301,L]
Now, give this one a little more try if it will work. If it's not, then find any suspicious why this code is not working:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^wfmenuconfig/family/family-disease/177-category-english /family-members/family-disease [R]
And go to http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$AnyNumber if it's redirecting into http://www.mydomain.com/en/family-members/family-disease just make sure that your web server have mod_rewrite.
I just wanted to throw this out there, I was also having trouble getting the RewriteRule to work. I have a client that upgraded to a WordPress powered site from .asp pages. What I had to do to get this to work is insert the RewriteCond and RewriteRule in the htaccess file BEFORE the "# BEGIN WordPress" section. Now it works just as it should.
This is posted way late, but hopefully it helps someone else out there running into the same issue.
Doesn't Work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
Does Work:
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Order of operations must be important =)
I want to allow access to specific domains. For example if domain contains the word asdf it should allow access. I final attempt before asking was:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^.*asdf.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} !^.*1234.*$
#RewriteRule .* - [F]
So here I tried to restrict access to all but domains that contain asdf or 1234.
You need to use %{HTTP_HOST} for checking the domain in URL instead of %{HTTP_REFERER}.
Can you try this code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^.*(asdf|1234)\. [NC]
RewriteRule .* - [F]
Anubhava gave me a clue but not with the http_host. Finally the problem was the OR.
Now the following worked like a charm:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^.*(1234|asdf).* [NC]
RewriteRule .* - [F]
So HTTP_REFERER did what it should do (check the domain accessing). And the | worked as the or argument I needed.
At some point through my error my localhost started getting redirected. After reading around I added RewriteCond !localhost [NC] to my .htaccess file and it now appears to work but I've pretty much no idea what I'm doing.
I don't know htaccess rules well, I've read several answers and googled but the scripts I've found seem to take a different approach usually based around...
Require valid-user
Allow from 127.0.0.1
Satisfy Any
...which I have trouble integrating.
Is my amend below OK or a bad idea?
# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^00\.00\.000\.000 # my remote IP address
RewriteCond !localhost [NC] # I added this line
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|zip) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
I would suggest you to remove these lines
RewriteCond %{REMOTE_ADDR} !^00\.00\.000\.000 # my remote IP address
RewriteCond !localhost [NC] # I added this line
and add just this:
RewriteCond %{REMOTE_ADDR} !^(?:(?:00\.00\.000\.000)|(?:127\.0\.0\.1))$
But the
Require valid-user
Allow from 127.0.0.1
Satisfy Any
Solution is much better.