Redirect to same domain with htaccess

Viewed 43

I want to redirect a user via htaccess when a specific HTTP_REFERRER is set. Here is my current htaccess

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.example.org [NC]
RewriteRule ^(.*)$ https://example.com/blocked/$1 [L,R]

The problem I am facing now is that the HTTP_REFERRER still persists and I end within an endles redirection to /blocked/blocked/blocked

Is there any easy way to simple redirect/forward the user just ones to /blocked?

1 Answers

You need to exclude the /blocked URI in Rewrite to avoid the loop error

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^(.*)\.example.org [NC]
RewriteCond %{REQUEST_URI} !/blocked
RewriteRule ^(.*)$ https://example.com/blocked/$1 [L,R]
Related