需要一些帮助在 apache 中利用 %{HTTP_REFERER}

Need some help leveraging %{HTTP_REFERER} in apache

我们有一个用例,其中如果请求 Request URI 以 /<path-info>(.*) 开头,则将用户重定向到 /fr-fr/404.hml。并且初始请求具有像 https://{host}/fr-fr/home.html 这样的推荐人。我有以下配置来处理用例,

RewriteCond %{REQUEST_URI} ^/<path-info>(.*)$
RewriteCond %{HTTP_REFERER} ^/(.*)/(.*).html(.*)$
RewriteRule (.*) /%1/404.html

但是,在测试过程中,我发现 {HTTP_REFERER} 没有按我的预期工作。 我已经使用 https://htaccess.madewithlove.be/ 测试了我的配置。有人可以帮我吗?

提前致谢。

你的规则是这样的:

RewriteCond %{REQUEST_URI} ^/test/abc/ [NC]
RewriteCond %{HTTP_REFERER} ^https?://[^/]+/([^/]+)/[^.]+\.html [NC]
RewriteRule ^ /%1/404.html [L,NC,R=302]

HTTP_REFERER 包含完整的 URL 即 scheme:host/uri.

我保留 R=302 用于测试目的。测试后,将其更改为 R=301 以使其永久重定向。