简体   繁体   English

在.htaccess中使用指令将HTTP流量有选择地重定向到https(Apache)

[英]Use directives in .htaccess to selectively redirect http traffic to https (apache)

I currently have a two mod_rewrite rules set up in my .htaccess file 我目前在.htaccess文件中设置了两个mod_rewrite规则

rewriteCond %{HTTP_HOST} ^mysite.org [NC]
rewriteRule ^(.*)$ https://www.mysite.org/$1 [R=301,L]

rewriteCond %{SERVER_PORT} =80
rewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI}

The former being to redirect any traffic from mysite.org -> https://www.mysite.org , the latter picking up anything on port 80 (http) and send it to https. 前者将重定向来自mysite.org-> https://www.mysite.org的所有流量,后者则在端口80(http)上拾取任何内容并将其发送到https。

But the admin control panel for my CMS is not accessible via https so I need to be able to access anything with the sub-domain mysite.org/admin via http. 但是我的CMS的管理控制面板无法通过https访问,因此我需要能够通过http访问mysite.org/admin子域。

Is this possible? 这可能吗?

You can create an exception for admin: 您可以为admin创建一个例外:

rewriteCond %{HTTP_HOST} ^mysite.org [NC]
rewriteRule ^(.*)$ https://www.mysite.org/$1 [R=301,L]

rewriteCond %{SERVER_PORT} =80
rewriteRule ^((?!admin).*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

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