.htaccess 重定向安全

发布于 2024-12-13 13:26:27 字数 662 浏览 0 评论 0原文

到目前为止尚未找到我要查找的内容。

我想将所有网站访问者重定向到他们输入的 URL 的安全版本,因此我已将其放入我的 .htaccess 文件中。

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]

到目前为止一切顺利,但现在我希望访问者输入

  • www.mywebsite.com/directory/param1/etcetera/
  • www.mywebsite.com/directory/file.php?param1 =value1

被重定向到

  • https://www.mywebsite.com/directory/param1/etcetera/
  • https://www.mywebsite.com/directory/file.php?param1=value1

也是如此,因为这没有发生。 有高手可以帮帮我吗? :) 谢谢

Haven't found what i'm looking for so far.

I want to redirect all my site visitors to the secure version of the URL they type in, so i've put this in my .htaccess-file.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]

So far so good, but now I want that visitors who type in

  • www.mywebsite.com/directory/param1/etcetera/ or
  • www.mywebsite.com/directory/file.php?param1=value1

are being redirected to

  • https://www.mywebsite.com/directory/param1/etcetera/ or
  • https://www.mywebsite.com/directory/file.php?param1=value1

as well, cause that isn't happening.
Can some guru help me out? :) thnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新雨望断虹 2024-12-20 13:26:27

您的第一个案例 www.mywebsite.com/directory/param1/etcetera/ 应通过您的 RewriteRule 重定向到其 https 变体。我不明白为什么那不起作用。

为了涵盖第二种情况,为了让 Apache 包含查询字符串,您需要添加 QSA 标志,所以:

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L,QSA]

Your first case, www.mywebsite.com/directory/param1/etcetera/, should be redirected to its https variant by your RewriteRule. I can't see why that wouldn't work.

To cover the second case, in order to have Apache include the query string, you need to add the QSA flag, so:

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文