.htaccess url为ssl https重定向重写 [英] .htaccess url rewrite for ssl https redirection

查看:171
本文介绍了.htaccess url为ssl https重定向重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其他问题的解决方案和互联网上使用了不同的代码。我真的不精通 htaccess 。已购买并确认正在使用SSL证书,但我很擅长应用这些重定向。

I've used different codes provided here on other questions' solutions and on the internet. I'm really not savvy with htaccess. Bought and confirmed working SSL Certificate, but I'm new to applying these redirects.

目标:
我需要在以下目录中将http重写为https。

  • http://mydomain.com/products-page/checkout
  • http://mydomain.com/products-page/your-account
  • http://mydomain.com/wp-login

我正在通过Dreamhost进行共享托管。如果有帮助,我有一个专用的IP。

I'm on shared hosting via Dreamhost. I have a dedicated IP, if that helps.

Dreamhost代表向我推荐的初始代码:

Initial code I was using recommended to me by a Dreamhost representative:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} wp-login 
RewriteRule ^(.*)$ https://mydomain.com/wp-login/$1 [R,L]


推荐答案

在文档根目录的htaccess文件中尝试这些规则。

Try these rules in the htaccess file in your document root.

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/wp-login|/products-page/checkout|/products-page/your-account)
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]

第一个条件检查请求是否不是HTTPS ,第二个检查请求是否以 / wp-login / products-page / checkout / products-page / your-account ,如果两者都适用,那么重写只需要整个URI并重定向到https://。

The first condition checks if the request isn't HTTPS, the second checks if the request starts with either /wp-login, /products-page/checkout, or /products-page/your-account, and if both apply, then the rewrite simply takes the entire URI and redirects to https://.

这篇关于.htaccess url为ssl https重定向重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆