Ashish
Ashish

Reputation: 114

How to block requests from domain other than mine?

I have a wordpress website say mydomain.in, Someone is using domain masking and able to open my website on their domain(lets say external.com) without my permission. I have this .htaccess rules but its not working.

<IfModule mod_rewrite.c>
RewriteEngine On


RewriteCond %{HTTP_REFERER} !mydomain.in
RewriteRule ^.*$ - [F]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule .* https://www.mydomain.in/? [R=301,L]
</IfModule>

But it still opens from their domain. What is the solution for this

Upvotes: 1

Views: 369

Answers (1)

anubhava
anubhava

Reputation: 785246

Have it like this:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(?:www\.)?mydomain\.in$ [NC]
RewriteRule ^ - [F]

RewriteRule ^index\.php$ - [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Take note of this new rule:

RewriteCond %{HTTP_HOST} !^(?:www\.)?mydomain\.in$ [NC]
RewriteRule ^ - [F]

That checks if HTTP_HOST of a request is not mydomain.in then simply block the request with 403 - Forbidden status.

Upvotes: 0

Related Questions