1

for my Magento site marketing I use backlink,so some backlinks are right and some others are not not ok I need to block my site access from unknow sites backlink.

i used htacces code but that not working

# ----------------------------------------------------------------------
# Allow loading of external fonts
# ----------------------------------------------------------------------
<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
    <IfModule mod_headers.c>
        SetEnvIf Origin "http(s)?://(www\.)?(google.com|staging.google.com|development.google.com|otherdomain.example|dev02.otherdomain.example)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
        Header merge Vary Origin
    </IfModule>
</FilesMatch> 

so now I think that I do it manually so that I need to check all request that comes from wich site s o any one can help me how can I check which request comes from wich site?

1 Answer 1

2

In Magento 2, you can use the HTTP_REFERER to check the source of a request. This header will contain the URL of the website that the request is coming from.

You can check the value of this header in the controller action that handles the request:

$referer = $this->getRequest()->getServer('HTTP_REFERER');
if ($referer && strpos($referer, 'yourdomain.com') === false) {
    // request is coming from an unknown website
}

You can also check this in the .htaccess file. You can deny all external domains except your own domain.

RewriteCond %{HTTP_REFERER} !^https?://(www\.)?yourdomain\.com/ [NC]
RewriteRule .* - [F]

It's worth noting that the HTTP_REFERER header can be easily spoofed, so it's not a foolproof method of identifying the origin of a request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.