Block Unwanted Domain Name Pointing to My Site - .htaccess

The domain name 2nicksplumbing.com that is privately registered is being indexed by Google and directed to NicksPlumbing.com
I have attempted the following to block it with no luck...
Blocked the domains ip in cPanel
Deny method in .htaccess file
RewriteCond method in .htaccess file (code below)
Can anyone suggest why I cannot block this domain name from pointing to our site?
Options +FollowSymLinks
RewriteEngine On
ErrorDocument 404 https://www.nicksplumbing.com/404.html
RewriteCond %{HTTP_REFERER} 2nicksplumbing\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_HOST} ^nicksplumbing\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^nicksplumbingrepair\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.nicksplumbingrepair\.com [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.nicksplumbing.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.nicksplumbing.com/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I see you've tried to block the domain using HTTP_REFERER, the other method to try is using the env=bad directive:
SetEnvIfNoCase Referer "2nicksplumbing\.com" bad_referer
SetEnvIfNoCase Referer "www\.2nicksplumbing\.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer
The above will allow access to your website from everything that isn't on your bad_referer list. For more information you can read the Apache Documentation for this.
Clear your cache before testing this.
I will add however, it doesn't seem like this private domain is doing harm to your website? It is simply referring traffic to your website.

Related

How to allow access to files for all sites while maintaining htaccess redirection

I wanted to keep the redirect rule. but I don't want to have to add site by site so that they can display the image. how can i change this rule so that it can do this trick? thanks in advance. Any help is welcome :)
actual htaccess
<Files ~ "\.(jpg|jpeg|png|gif)$">
Order allow,deny
allow from all
</Files>
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)fbclid=
RewriteRule ^ / [L,R=permanent]
RewriteCond %{HTTP_REFERER} !^https://mysite,com [NC]
RewriteCond %{HTTP_REFERER} !^https://www.facebook,com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.facebook,com/ [NC]
RewriteCond %{HTTP_REFERER} !^https://externalsite,com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://externalsite2,com/ [NC]
RewriteCond %{HTTP_REFERER} !^https://mysite,com.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ https://mysite,com [NC,R,L]
<IfModule mod_php4.c>
php_value engine off
</IfModule>
<IfModule mod_php5.c>
php_value engine off
</IfModule>
<Files ~ "\.((php[0-9]?)|p?html?|pl|sh|java|cpp|c|h|js|rc)$">
Order allow,deny
Deny from all
</Files>
RewriteCond %{HTTP_REFERER} !^https://mysite,com [NC]
RewriteCond %{HTTP_REFERER} !^https://www.facebook,com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^https://www.facebook,com/ [NC]
RewriteCond %{HTTP_REFERER} !^https://externalsite,com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://externalsite2,com/ [NC]
RewriteCond %{HTTP_REFERER} !^https://mysite,com.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ https://mysite,com [NC,R,L]
I wanted to give full access to other sites to incorporate my content ... redirecting if you access the file directly at example.com/uploads/test.gif
If you simply want to block direct access (in which case the Referer header is empty) and allow all other sites to link to your images (basically the opposite of "hotlink protection") then you can replace the above rule (that redirects such requests to the root) with the following:
RewriteCond %{HTTP_REFERER} ^$
RewriteRule \.(jpg|jpeg|png|gif)$ https://example.com/ [NC,R,L]
This redirects all direct requests to the root / home page.
(You had erroneous commas , in your original directives that would have prevented this from working?!)
HOWEVER, basing this redirect on the HTTP Referer is unreliable - you will get false positives. The Referer is sent by the browser - so the user can control (and suppress) what is sent. The website that is linking to you can also set a referrer-policy that suppresses the HTTP Referer being sent - so all requests from some sites might look like direct requests anyway and end up being blocked. There is no way around this.

htaccess RewriteCond not working after forcing https

I have some rules that deny access to a contact form from certain IP addresses as below
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
#restrict access to contact form
RewriteCond %{REQUEST_URI} ^.(index.php/)?contact(.*) [NC]
RewriteCond %{REMOTE_ADDR} ^81\.136\.137\.239
RewriteRule ^(.*)$ / [F,L]
Before I put the https rewrite in the restrictions to the contact form worked OK.
After forcing all traffic to https I am able to get to the contact form even from IP addresses specifically restricted.
Is there something in the REQUEST_URI line that is not picking up https connections? (I would like it to restrict access on both http and https if possible but if not then just https)
Go to contact folder and make .htaccess and put the following code inside it :
deny from 81.136.137.239
if you have more IP add them like example above
update
If it is file try this :
RewriteEngine On
RewriteCond %{REQUEST_URI} contact
RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.239
RewriteRule ^(.*)$ / [F,L]
For more IPs :
RewriteEngine On
RewriteCond %{REQUEST_URI} contact
RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.239 [OR]
RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.230 [OR]
RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.220
RewriteRule ^(.*)$ / [F,L]

www htaccess redirect with segment in url

Where my site is hosted, I'm using .htaccess and it has a condition to remove the www and direct to the main page without the www.
<ifModule mod_rewrite.c>
Header set X-Frame-Options DENY
RewriteEngine On
# Required to allow direct-linking of pages so they can be processed by Angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://meusite.com.br [R=301,L]
</ifModule>
The problem is this, when someone accesses an internal page with www, it falls for this check and is directed to the home, example:
If someone accesses the link: http://www.meusite.com.br/conteudo/94-vai-criar-um-site-to-your-employee-said-you-can-noble
It will direct to http://meusite.com under the condition.
What I need, is that it is directed to the following link: http://meusite.com/content/94-vai-create-a-site-to-your-employee-behavior-which-cannot-can- -fine only by removing the www from the link.
Does anyone know if this check is possible in .htaccess?
EDIT:
.htaccess is not able to translate your titles from portugese to english.
You should do redirection to normal domain with full link, and then do internal redirection with your backend (i.e. php, ruby) to proper translated link.
Use following code before your redirection, so links with conteudo will be catched here and redirected properly using backreferences:
RewriteCond %{HTTP_HOST} ^www\..* [NC]
RewriteRule ^\/conteudo\/(.*)$ http://menusite.com.br/content/$1 [R=301,L]
Soluction:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

How to implement dynamic subdomains in codeigniter with .htaccess?

How can I implement dynamic subdomains in codeigniter with .htaccess?
Make sure that subdomains are enabled on your site. When you enter test.yoursite.com it should take you to the welcome page of your site. If instead it gives DNS lookup error then it means subdomains is not enabled on your site.
To enable subdomains on your site add *.yoursite.com entry to the DNS Zone records.
Second insert the following code in your .htaccess file and replace yoursite appropriately.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#codeigniter specific rule
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#this rule removes www from the URL if its used
RewriteCond %{HTTP_HOST} ^www.
RewriteRule ^(.*)$ http://yoursite.com/$1 [R=301,L]
#the auth system URIs which don't have subdomains
RewriteCond %{HTTP_HOST} ^yoursite.
RewriteRule ^(signup|signin|forgot_password)/?$ index.php?/auth/$1 [L]
#this rule handles the subdomains
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).yoursite.com
RewriteRule ^(.*)$ index.php?/public_site/%1/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Add more rules, if necessary, for handling auth system or subdomains. I know I did for my site to get pretty URIs.
Important Note:
I found that by default the subdomain URIs work very well with codeigniter without any of the above rules. You can access all of your site with test.yoursite.com/# URI instead of www.yoursite.com/#. But the URIs are not pretty and there would be more than one way to access a URI.
So if you use the above rules it will give you pretty URIs and, more importantly, will give you unique URIs. So if you use the above rules you will only get one URI for the signup page and that is http://yoursite.com/signup.
this code is working for my site, you can move your site into your other domain or folder ( whatever you want ).
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|application/assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
This rule handles the subdomains
RewriteCond %{HTTP_HOST} ^([a-z0-9]+).yoursite.com. should probably also include the hypen -. RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).yoursite.com.

hiding index.php and all the variables from url

I'am using a mod_rewrite to get the virtual subdomain as a variable in my site
and would like to add a rule to hide the index.php and all the variables in the url
but can't get it to work. Any suggestions please?
This is my actual .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$
RewriteCond %{HTTP_HOST} ^(.*)\.mysite\.com$
RewriteRule ^$ /index.php?member=%1 [P,L]
Your best bet is probably to send in a support ticket and have the domain wildcarded.
.htaccess seems perfect.
Detail Description:
You will need to ask hosting company to add "wild-card" DNS set up to forward all subdomains to Web root directory. For example *.domain.com to www.domain.com. They can do this by adding A entry in DNS setting
HTACCESS Code
<IfModule mod_rewrite.c>
# Redirect to user blog (with any trailing path)
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9]).example.com(.*)$ [NC]
RewriteRule ^(.*)$ /index.php?member=$1 [R=301,L]
## Otherwise, force www;
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
</IfModule>

Resources