使用 htaccess 重定向到同一个域

Redirect to same domain with htaccess

我想在设置特定 HTTP_REFERRER 时通过 htaccess 重定向用户。这是我当前的 htaccess

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

我现在面临的问题是 HTTP_REFERRER 仍然存在,我最终会无休止地重定向到 /blocked/blocked/blocked

有什么简单的方法可以让 redirect/forward 用户只需要 /blocked 吗?

您需要在 Rewrite 中排除 /blocked URI 以避免循环错误

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