【问题标题】:RewriteCond and RewriteRule in .htaccess.htaccess 中的 RewriteCond 和 RewriteRule
【发布时间】:2010-11-16 00:13:10
【问题描述】:

我有一个位于http://www.example.com/client 的客户端文件夹 但是,我现在已经在服务器上安装了 SSL,并希望使用 HTACCESS 添加一个永久重定向,以便每当访问 /client 时,它都会重定向到:https://www.example.com/client

有人知道怎么做吗?

我过去曾像这样重定向我的域:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

这应该不会影响解决方案,但站点仍必须先重定向到 www.example.com,然后再重定向到 https://www.example.com/client,例如输入 http://www.example.co.za/client

【问题讨论】:

标签: apache .htaccess mod-rewrite


【解决方案1】:

试试这个:

RewriteCond %{HTTPS} !on
RewriteRule ^client(/.*)?$ https://www.example.com%{REQUEST_URI} [L,R=301]

【讨论】:

    【解决方案2】:

    重写引擎开启 重写规则 ^/?$ https://www.example.com/client [301,NC,L]

    它告诉 apache,只要 url 是 https://www.example.com 或结尾带有斜杠,就会重定向到你的 /client

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      相关资源
      最近更新 更多