gpt4 book ai didi

apache - 标题未设置 RewriteRule [R=302,L]

转载 作者:行者123 更新时间:2023-12-03 17:05:49 24 4
gpt4 key购买 nike

目标:我正在尝试通过 htaccess 设置两个 header :

X-Robots-Tag: noindex, nofollow
Location: http://example.com/foo

概念验证:在 PHP 中可以做到这一点,效果很好:
header( "X-Robots-Tag: noindex, nofollow", true );
header( "Location: " . $url, 302 );

问题:在我的 .htaccess文件我有这个:
# Do not let robots index anything from /out/
RewriteCond %{REQUEST_URI} ^/?out/?
Header set X-Robots-Tag "noindex, nofollow"

...

# Redirect /out/example/ type links
RewriteRule ^/?out/example/(.*)$ "http://example.com/$1" [R=302,L]

我确定某处有一个我没有看到的简单错误,但是如果我检查标题,例如 http://localhost/out/example/foo , Location header 已设置,但 X-Robots-Tag不是。
HTTP/1.1 302 Found
Date: Wed, 08 Jun 2016 23:59:18 GMT
Content-Type: text/html; charset=iso-8859-1
Transfer-Encoding: chunked
Connection: close
Location: http://example.com/foo
...

但是,触发 404(例如 http://localhost/out/404 )将设置适当的 header :
HTTP/1.1 404 Not·Found
Date: Wed, 08 Jun 2016 23:56:19 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding,User-Agent
X-Robots-Tag: noindex, nofollow <--- set
...

问题出在哪儿?

最佳答案

解决方案是执行以下操作:

# Redirect /out/example/ type links
RewriteRule ^/?out/example/(.*)$ "http://example.com/$1" [R=302,L,E=OUTLINK:1]

# Add the robots header if E was set above
Header always set X-Robots-Tag "noindex, nofollow" env=OUTLINK

注:这是一个挑战,因为最初的解决方案是将“noindex”标题添加到杀死我网站的所有内容中。我希望这对 future 的人有所帮助。

关于apache - 标题未设置 RewriteRule [R=302,L],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37715136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com