: How do I integrate rewrite rules to forbid requests referred from a domain with existing rewrite rules in .htaccess? I have read about how to do this using the following: <IfModule
I have read about how to do this using the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https?://([^.]+.)*website.com [NC]
RewriteRule .* - [F]
</IfModule>
However, I can't figure out how to use it in combination with what is currently there now:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
More posts by @Looi9037786
1 Comments
Sorted by latest first Latest Oldest Best
block a domain
You presumably mean "block a referer".
You just need to put that bit of code before the existing directives. Otherwise, if you put it at the end (after the front controller) then it will never be processed.
You don't need the additional <IfModule> wrapper and certainly not the additional RewriteEngine directive (although it does no harm). For example:
RewriteCond %{HTTP_REFERER} ^https?://([^.]+.)*website.com [NC]
RewriteRule .* - [F]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
In fact, you probably don't need the <IfModule> wrapper at all - but if this is auto-generated by your CMS (eg. WordPress) then leave it.
But otherwise...
RewriteEngine On
# Block
RewriteCond %{HTTP_REFERER} ^https?://([^.]+.)*website.com [NC]
RewriteRule .* - [F]
# Front controller
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.