Mobile app version of vmapp.org
Login or Join
Looi9037786

: 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

@Looi9037786

Posted in: #Domains #Htaccess

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>

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Looi9037786

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme