Htaccess file redirects wrong ip's - html

I'm trying to redirect spam ip's from my website to a different website.
For some reason the following code in my .htaccess file redirects me (my ip) to the www.underconstruction.com despite my ip not being included. My ip has the following format 5.64...
Please, could you help me improve the following code so that it redirects only the listed ip's / ip ranges to www.underconstruction.com
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^88\.208\.201\.208 [OR]
RewriteCond %{REMOTE_ADDR} ^209\.190 [OR]
RewriteCond %{REMOTE_ADDR} ^209\.51 [OR]
RewriteCond %{REMOTE_ADDR} ^5\.101 [OR]
RewriteCond %{REMOTE_ADDR} ^62\.210 [OR]
RewriteCond %{REMOTE_ADDR} ^62\.212
RewriteRule ^/* http://www.underconstruction.com/ [L]

Have you checked your error log? Try to use REMOTE_HOST instead of REMOTE_ADDR

The problem can be solved by using the following code in the .htaccess file. The REMOTE_HOST parameter has been used instead of the REMOTE_ADDR
RewriteEngine On
RewriteCond %{REMOTE_HOST} ^88\.208\.201\.208 [OR]
RewriteCond %{REMOTE_HOST} ^209\.190 [OR]
RewriteCond %{REMOTE_HOST} ^209\.51 [OR]
RewriteCond %{REMOTE_HOST} ^5\.101 [OR]
RewriteCond %{REMOTE_HOST} ^62\.210 [OR]
RewriteCond %{REMOTE_HOST} ^62\.212
RewriteRule ^/* http://www.underconstruction.com/ [L]

Related

How To make Custom Links Without Showing page not found error [duplicate]

I want to redirect all pages on my site (including index) to UnderWork.html
and I'm doing this using .htaccess with this code:
RewriteEngine on
RewriteRule ^(.*)$ UnderWork.html
...and its works fine.
Now I am adding some more code to my .htaccess to redirect all traffic to the non-www domain and now my code looks like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.in
RewriteRule ^(.*)$ http://domain.in$1 [R=permanent,L]
RewriteRule ^(.*)$ UnderWork.html
Here is where I have a problem. If I enter a URL like: domain.in/xyz then it works as before, but if I use a URL like: www.domain.in/xyz then Apache converts it to coincart.inxyz/.
What am I doing wrong here? How can I get what i want? Thanks in advance.
Below are rules that work for me:
RewriteEngine On
# Adding trailing slash for directory requests.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/www$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.+[^/])$ http://example.com/$1/ [R=permanent]
# External redirection from www subdomain to non-www domain.
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^/?(.*) http://example.com/$1 [L,R=permanent]
# Internal redirection to index.php for nonexistent URLs.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|png|gif)$
RewriteRule . /index.php [L,QSA]
To show a custom page when a directory root (domain root in particular) is requested, use the Apache's DirectoryIndex directive:
DirectoryIndex UnderWork.html

Combining HTAccess rules into one

Hey everyone im trying to use Htaccess to redirect all pages to https:// while keeping the query string without fbclid if it's there.
IE.
https://www.example.com/?sdfuh
http://www.example.com/?sdfuh
www.example.com/?sdfuh
https://www.example.com/?sdfuh&fbclid=azduh
http://www.example.com/?sdfuh&fbclid=azduh
www.example.com/?sdfuh&fbclid=azduh
example.com/?sdfuh&fbclid=azduh
They should return https://example.com/?sdfuh
Ok so after some help Ive got to this
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [AND]
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)fbclid=(?:[^&]*)((?:&|$).*)$ [NC]
RewriteRule ^(.*)/?(.*)$ https://example.com/?%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [AND]
RewriteCond %{QUERY_STRING} ^(.*)
RewriteRule ^(.*)/?(.*)$ https://example.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(.*)/?(.*)$ https://example.com/ [R=301,L]
RewriteCond ^(www.)?example.com$
RewriteRule ^(.*)/?(.*)$ https://example.com/ [R=301,L]
This works with:
https://www.example.com/?sdfuh
http://www.example.com/?sdfuh
www.example.com/?sdfuh
https://www.example.com/?sdfuh&fbclid=azduh
http://www.example.com/?sdfuh&fbclid=azduh
Not with
www.example.com/?sdfuh&fbclid=azduh
example.com/?sdfuh&fbclid=azduh
I need to figure out how to make it shorter and work with all the possibilities
Rather than literally combining the rules, I believe the main piece of knowledge you are missing out on is the use of [OR] - which means a RewriteRule won't fail if only one of the RewriteCond results in true.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [OR]
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)fbclid=(?:[^&]*)((?:&|$).*)$ [NC]
RewriteRule ^(.*)/?(.*)$ https://example.com/?%1%2 [R=301,L]
You can test this out here: https://htaccess.madewithlove.be?share=f4381086-80b4-52b6-883e-8921f5de2316
After alot of help this solved my issue of stripping facebooks tracker, keeping my own query string and confirming https:// is used.
RewriteCond %{QUERY_STRING} ^(.*)(?:^|&)fbclid=(?:[^&]*)((?:&|$).*)$ [NC]
RewriteRule ^(.*)/?(.*)$ https://example.com/?%1%2 [R,N]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)/?(.*)$ https://example.com/$2 [R,L]

htaccess Allow only internal IP

RewriteCond %{REMOTE_ADDR} !=173.220.70.101 [OR,NC]
RewriteCond %{REMOTE_ADDR} !=173.220.70.102
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I would like to have a or statement for two IP address
the old version worked for one IP
not sure why this isn't working anymore.
Use:
RewriteCond %{REMOTE_ADDR} !=173.220.70.101
RewriteCond %{REMOTE_ADDR} !=173.220.70.102
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Without [OR]...
Allowing only 173.220.70.1 and 173.220.70.2
RewriteCond %{REMOTE_ADDR} !^173.220.70.[1-2]$
RewriteRule ^.* - [F]
Allowing any IP except 173.220.70.1 and 173.220.70.2
RewriteCond %{REMOTE_ADDR} ^173.220.70.[1-2]$
RewriteRule ^.* - [F]

Prevent AddOn domain from redirecting to subdomain (Bluehost)

Hi my AddOn domain keeps on redirecting to a subdomain.
I also noticed that this also happens when I try accessing the folder where I pointed the AddOn domain
AddOn Domain: addon.com
Subdomain: addon.maindomain.com
Subfolder: maindomain.com/addon
Why is this so? I've seen from the Domain Manager a message like this though.
Addon Parent: The domain addon.com is aliased to addon.maindomain.com
How can I prevent the redirection from happening?
Try either of these:
file: maindomain/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/addon/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
or
file: maindomain/addon/.htaccess
writeEngine On
RewriteCond %{HTTP_HOST} ^addon.maindomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.addon.maindomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^addon.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ http://www.addon.com/ [R=301,L]
Cheers!
Ref:
https://my.bluehost.com/cgi/help/498
https://my.bluehost.com/cgi/help/134

Exclude certain subfolders and domains in redirects

This is a continuation from Redirect only HTML files?
How can I change my .htaccess to make it exclude certain subfolders or subdomains from the HTML-only redirect? I tried doing using this code to exclude the 'downloads' subfolder and the 'dev' and 'support' subdomains, but it didn't work:
RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} !download [OR]
RewriteCond %{HTTP_HOST} !faq
RewriteCond %{HTTP_HOST} !support [OR]
RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]
You need to check REQUEST_URI or the whole match of the RewriteRule $0 for this; HTTP_HOST does only contain the host name of the current request. You also need to change the logical expression of your condition:
RewriteCond %{HTTP_HOST} ^pandamonia\.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia\.us$
RewriteCond %{REQUEST_URI} !^/download/
RewriteCond %{REQUEST_URI} !^/faq/
RewriteCond %{REQUEST_URI} !^/support/
RewriteRule /.+\.html$ http://pandamonia.us/ [L]
For those looking for a quick bit of insight into Gumbo's previous reply (where he mentions the situations for when to (and not to) use [OR], I found this WMW thread very helpful: http://www.webmasterworld.com/apache/3522649.htm