.htaccess http to https redirect [closed]

2019-03-06 05:17发布

问题:

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]

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.

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.

(Basically I need an exact copy of the htaccess from molten-wow.com)

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.

Thanks in advance

回答1:

Try

#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]


回答2:

Here is an idea:

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