Ste*_*ski 9 mod-rewrite redirect apache-2.2 apache-2.4
这是一个 Apache httpd 2.2 服务器。
我们要求对该网络服务器的访问通过 HTTPS 加密。
当 Web 客户端访问我位于http://www.example.org/ $foo(端口 80)的站点时,我想将他们的请求重定向到位于https://www.example.org/ $foo的 HTTPS 加密网站。
似乎有两种常见的方法可以做到这一点:
第一种方法使用来自 mod_alias的“重定向”指令:
<VirtualHost *:80>
Redirect permanent / https://www.example.org/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
第二种方法使用 mod_rewrite:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
“永久重定向”和 mod_rewrite 节之间有什么区别。一个比另一个更好吗?
默认情况下,mod_rewrite 会执行临时的“302 Found”重定向。假设其他一切都相等,Redirect permanent则等价于RewriteRule <blah> [R=permanent]。
一个比另一个更好吗?
Apache 现在推荐使用Redirectfrommod_alias而不是使用RewriteRulefrom mod_rewrite。请参阅https://httpd.apache.org/docs/current/rewrite/avoid.html#redirect,其中说:
当发现需要其他替代方案时,应将 mod_rewrite 视为最后的手段。当有更简单的替代方案时使用它会导致配置混乱、脆弱且难以维护。
| 归档时间: |
|
| 查看次数: |
8016 次 |
| 最近记录: |