ModRewrite使用HTTPS [英] ModRewrite with HTTPS

查看:232
本文介绍了ModRewrite使用HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的MOD重写,以确保不仅规范的URL,也就是使用HTTPS显示的网站:

I'm using the following mod rewrites to ensure not only canonical URLs, but also that the site is displayed using HTTPS:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
// It think the problem must be here --^

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php?
RewriteRule ^index\.php?$ https://www.rto12.ca/ [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?
RewriteRule ^index\.html?$ https://www.rto12.ca/ [R=301,L]

当你试图去这里我的问题来了: rto12.ca ...浏览器需要您在这里:`的 https://www.rto12.ca/https://rto12.ca/

My problem comes when you try to go here: rto12.ca... The browser takes you here: `https://www.rto12.ca/https://rto12.ca/'

这是第一个条件/规则导致此。任何建议将是AP preciated。

It's the first condition/rule that's causing this. Any suggestions would be appreciated.

推荐答案

这条规则:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

...只是重写请求 https://rto12.ca/REQUEST_URI ,然后将其传递给下一条规则(将输入到下一个通常,你追加到请求的结束,将 https://rto12.ca/REQUEST_URI )。然而,它才能正常工作,你需要它立即重定向:

...will just rewrite the request to https://rto12.ca/REQUEST_URI, and then pass it off to the next rule (the input to the next rule, which you append to the end of the request, will be https://rto12.ca/REQUEST_URI). However, for it to work properly, you need it to redirect immediately:

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

很可能可能所有的规则组合成最多为一个重定向,所以让我与它玩了一下,我会看看我能想出的话,我会更新的答案。添加标志应该解决您的问题无论哪种方式,虽然。

It's likely possible to combine all of your rules into at most a single redirect, so let me play around with it a bit and I'll see what I can come up with, then I'll update the answer. Adding the flags should fix your problem either way, though.

修改:我觉得这应该采取一切一气呵成:

Edit: I think this should take everything in one go:

RewriteEngine On

RewriteCond %{HTTPS}        =off   [OR]
RewriteCond %{HTTP_HOST}   !^www\. [OR]
RewriteCond %{THE_REQUEST}  ^[A-Z]{3,9}\ /index\.(html|php)
RewriteCond %{HTTP_HOST}    ^(www\.)?(.+)$
RewriteRule ^(index\.(html|php))|(.*)$ https://www.%2/$3 [R=301,L]

这篇关于ModRewrite使用HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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