.htaccess 将子文件夹重定向到 HTTPS [英] .htaccess redirect subfolder to HTTPS
问题描述
我正在尝试为我的 .htaccess 文件编写 RewriteRule.具体来说,每当用户访问特定的子目录时,我希望它重写以强制进行 HTTPS 连接.
I'm trying to write a RewriteRule for my .htaccess file. Specifically, whenever a user accesses a specific subdirectory, I would like it to Rewrite to force an HTTPS connection.
例如,每当有人访问:http://www.mydomain.com/subdirectory
(以及该子目录"的任何其他子目录).
For example, whenever someone accesses: http://www.mydomain.com/subdirectory
(and any other sub-directories of that "subdirectory").
我希望它重写为 https://www.mydomain.com/subdirectory
我尝试了以下方法,但它似乎创建了一个循环:
I've tried the following, but it appears to create a loop:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/subdirectory/$1 [R=301,L]
此外,此 .htaccess 文件位于我的域的根目录中.
Also, this .htaccess file is placed in the root of my domain.
关于如何修改我的 RewriteRule 的任何想法?
Any ideas on how to modify my RewriteRule?
非常感谢!
推荐答案
我会把它放到域的根目录中:
I would put this into the domain's root directory:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(subdirectory/.*)$ https://www.mydomain.com/$1 [R=301,L]
这篇关于.htaccess 将子文件夹重定向到 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!