How to redirect all useragent except useragent wget ? what to add?
SetEnvIf User-Agent .*Wget* wget
Order deny,allow
Deny from all
Allow from env=wget
You could just add a "redirecting" ErrorDocument directive to your existing directives. For example:
ErrorDocument 403 https://example.com/url/to/redirect/to
When combined with your existing directives (that "block" all other User-Agents) this will trigger a 302 (temporary) redirect to the stated URL for anything other than wget.
Alternatively, replace your existing directives with the following mod_rewrite rule instead:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !Wget
RewriteRule ^ https://example.com/url/to/redirect/to [R=302,L]
Both of these assume the URL you are redirecting to maps to a different server, otherwise, you'll like get a redirect loop.
Related
I have a htaccess file with following code when trying to block an IP:
DirectoryIndex index.php index.html
ErrorDocument 404 /errors.php
Order Allow,Deny
Deny from 188.143.232.
Allow from all
Blocking my own IP works when browsing www.example.com, but it does not block for anything else (like www.example.com/index.php or www.example.com/home, ....). The htaccess is located in the same directory as index.php (httpdocs folder).
How can I get it to work?
You can also use a mod-rewrite based ip-blocking to block unwanted ip(s) :
RewriteEngine on
#--if client ip==188.143.232
RewriteCond %{REMOTE_ADDR} ^188\.143\.232
#--forbid the request
RewriteRule ^ - [F,L]
I'm getting tons of requests on my site based on an old url (get variable) structure. Its not something humans follow, so instead of redirecting it I want to block it so it uses almost 0 resources from server.
If the url contains something like thewebsite.com/?s=bla&some_variable=1 I want to block it with prejuduce!
This is what I have but it does not seem to work.
<FilesMatch "some_variable=1$">
order allow,deny
deny from all
</FilesMatch>
What am I doing wrong here?
You could parse query string with mod_rewrite and QUERY_STRING.
You can put this code in your root htaccess
RewriteEngine On
RewriteCond %{QUERY_STRING} some_variable=1 [NC]
RewriteRule ^ - [F]
Note: don't forget to check if mod_rewrite is enabled
Using Joomla and trying to stop using JoomFish, but for the time we did use it, other sites linked to our pages as "basedomain.org/en/everypage". Now those links go to 404 errors.
How do I use .htaccess to rewrite or redirect all requests for basedomain.org/en/everypage to basedomain.org/everypage??
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^en/(.*)$ /$1 [L,R=302]
Once you've confirmed it works, change 302 to 301. (301 is very hard to debug because browsers cache it)
Or, use a RedirectMatch (simpler, and no need to enable the RewriteEngine):
RedirectMatch permanent /en/(.*) http://www.example.com/$1
(replace www.example.com with your own domain)
We've moved a site to another domain and setup the htacess as bellow, but how can i set a rule "if page dosnt exist - (ie 404 error) redirect to new site homepage." To be used as a fall back, if someone follows a broke url to our old site.
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://oldsite.co.uk/$1 [R=301,L]
Redirect permanent http://oldsite.co.uk http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/index.html http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/contact-us.html http://newsite.co.uk/contact-us.html
Redirect permanent http://oldsite.co.uk/bespoke-furniture.html http://http://newsite.co.uk/bespoke-furniture.html
Redirect permanent http://oldsite.co.uk/about-us.html http://newsite.co.uk/about-us.html
Redirect permanent http://oldsite.co.uk/how.html http://newsite.co.uk/about-us.html
order deny,allow
You could simply use this.
ErrorDocument 404 http://newsite.co.uk
I have a folder on my site (domain.com/protect) I want to limit to only one referrer (otherdomain.com/subfolder).
Deny for all others, allow only if coming from that URL.
If not coming from that URL, then redirect the visitor over to otherdomain.com/login instead.
How would I write that out in .htaccess rewrite rules?
In the htaccess file in your /protect directory, add these rules:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !otherdomain\.com/subfolder
RewriteRule ^ - [L,F]
The condition checks that the referer doesn't contain: otherdomain.com/subfolder, and if it doesn't, then whatever the request is (inside the /protect directory) will result in a 403 Forbidden.
Alternatively, you can put these rules in the htaccess file in your document root if you would rather keep everything in once place:
RewriteEngine On
RewriteCond %{HTTP_REFERER} !otherdomain\.com/subfolder
RewriteRule ^/?protect/? - [L,F]