htaccess带有URL重写的SSL重定向

htaccess带有URL重写的SSL重定向

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

问题描述

我需要你的帮助.假设这是我的网站:example.com

I need your help.Let's say this is my website: example.com

我想将http重定向到https.此外,我还要重写网址.如果我通过以下方式访问该网站:

I would like to redirect http to https.Furthermore I would like also rewrite the url.If i access the website with:

https://example.com/new一切正常.

如果我通过以下方式访问网站:http://www.example.com/new它将重定向到https,但不会重写该URL.结果是这样的:

If I access the website with:http://www.example.com/new it redirects to https but will not rewrite the url. The result is this:

`https://example.com/old`


RewriteEngine on

RewriteRule  ^new/(.*)$    old/$1    [L,QSA]

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

我试图将规则放到另一个顺序,但这根本不起作用.

I have tried to put the rules in another order but this wasn't working at all.

希望您能帮助我.非常感谢:)

I hope you can help me. Many thanks:)

推荐答案

如果您只想删除www,则只需要这样做.

If you are only trying to remove www, you just need this.

RewriteEngine on

RewriteCond %{HTTPS} ^off [OR]
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]

RewriteRule  ^new/(.*)$    old/$1    [L,QSA]

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

08-20 07:56