首先,您希望它是临时重写 (=302) 还是浏览器应将其保存为 permanent 并因此得到 301?只是问,两者都有效,但如果你想暂时去,你应该阅读this
Excerpt: HTTP/1.1 (RFC 2616) added the new status codes 303 and 307
所以在你的情况下,307 可能会更好。
如果您想要永久重写,请使用[R=301] 使浏览器缓存重写目标,而不是每次都重写。
现在到 错误 解决方案(但我离开那里有一个好的原因,请参阅here) - 不要使用它! !
#logic is: 1 OR (2 AND 3) --> NO, it isn't, see the link right above!
#1 being hostname: somebody.dev.www.example.com
#2 being hostname: example.com
#3 being REQUEST_URI = !^/(top_deal|watches)
RewriteCond %{HTTP_HOST} ^somebody.dev.www.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !^/(top_deal|watches)$
RewriteRule .? - [END]
##[END] makes the rewrite-evaluation STOP, completely, not only for this turn!
#same rule as before, just changed 302 -> 307 (RFC 2616) and ^(.*)$ to .? cuz I like it better^^
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule .? http://%{HTTP_HOST}%{REQUEST_URI} [L,R=307]
更新
下面是真正应该放入配置的内容:
# Don't rewrite HOST 'somebody.dev.www.example.com'
RewriteCond %{HTTP_HOST} ^somebody.dev.www.example.com$
RewriteRule ^ - [END]
# Don't rewrite HOST 'example.com', if URI 'top_deal' OR 'watches'
RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} ^/(top_deal|watches)$
RewriteRule ^ - [END]
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=307]
这绝对可以完成这项工作:)
如果没有,由于某种原因,搜索您的LogLevel 并将rewrite:traceX 添加到该行。所以如果你的LogLevel 是error 它应该是这样的:
LogLevel error rewrite:trace2
然后重新启动/重新加载您的服务器并再次测试。 Error.log 现在将显示尝试重写的结果。使用tail -f error_log|fgrep '[rewrite:' 找到它们。如果他们不清楚,请告诉我们,也许我们可以提供帮助:)