简体   繁体   English

.htaccess-如何将http://重定向到https://以获取特定的URL

[英].htaccess - how to redirect http:// to https:// for specific url

How to redirect from http to https for specific url. 如何从http重定向到https以获取特定的URL。 For example, i need to have https for: 例如,我需要具有https:

mysite.com/page1

I don't need https for: 我不需要https:

mysite.com/page2,  mysite.com/page3

Use redirect. 使用重定向。 It will redirect with to https page with code 301 它将使用代码301重定向到https页面

Redirect 301 /page1 https://www.domaincom/page1

You can use this rule as your first rule in your DOCUMENT_ROOT/.htaccess file: 您可以将此规则用作DOCUMENT_ROOT/.htaccess文件中的第一条规则:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /page1[?\s] [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Redirect 301 /page1 https://domaincom/page1

This is working, but I have confict with another rule 这是可行的,但是我与另一条规则冲突

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

which is rewriting https://domaincom/page1 into http://domaincom/page1 https:// domaincom / page1重写为http:// domaincom / page1

How to get working of both rules? 如何使这两个规则生效?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM