.htaccess http到https重定向 [英] .htaccess http to https redirect
问题描述
我目前正在使用以下htaccess将我的网站重定向到https和www,如果尚未使用它。
I am currently using the following htaccess to redirect my site to https and www if not already using it.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
但是,我有一个子域forum.example.com,无法重定向到https,因为它是一个论坛,内容不安全。
However, I have a subdomain forum.example.com that cannot be redirected to https as it is a forum and has content that isn't secure.
当我在htaccess中使用上述代码时,它会将论坛重定向到 https://www.example .com / forum 而不仅仅是forum.example.com。
When I use the above code in my htaccess, it redirects the forum to https://www.example.com/forum instead of just forum.example.com.
(基本上我需要一份来自molten-wow.com的htaccess的精确副本)
(Basically I need an exact copy of the htaccess from molten-wow.com)
注意他们有https,但论坛没有重定向。
Notice how they have https, but the forum does not redirect.
有什么建议吗?如果我不清楚或者你需要澄清任何事情请告诉我,我会澄清。
Any advice? If I am being unclear or you need clarification on anything please let me know and I'll clarify.
提前致谢
推荐答案
尝试
#if not forum.example.com, not www.example.com and not ssl then redirect
RewriteCond %{HTTP_HOST} !^forum\.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R,L]
#if not forum.example.com, www.example.com, and not ssl then redirect
RewriteCond %{HTTP_HOST} !^forum\.
RewriteCond %{HTTP_HOST} ^www\.
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
#redirect if https://forum.example.com
RewriteCond %{HTTP_HOST} ^forum\.
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://forum.%{HTTP_HOST}/$1 [R,L]
这篇关于.htaccess http到https重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!