0

I have a folder on my site (domain.com/protect) I want to limit to only one referrer (otherdomain.com/subfolder).

Deny for all others, allow only if coming from that URL.

If not coming from that URL, then redirect the visitor over to otherdomain.com/login instead.

How would I write that out in .htaccess rewrite rules?

4

1 回答 1

0

在您/protect目录中的 htaccess 文件中,添加以下规则:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !otherdomain\.com/subfolder
RewriteRule ^ - [L,F]

该条件检查引用者不包含:otherdomain.com/subfolder,如果不包含,则无论请求是什么(在/protect目录内)都会导致 403 Forbidden。

或者,如果您希望将所有内容保存在一个位置,则可以将这些规则放在文档根目录的 htaccess 文件中:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !otherdomain\.com/subfolder
RewriteRule ^/?protect/? - [L,F]
于 2013-01-18T22:28:14.733 回答