Redirecting http subdomain to https subdomain

Hello,

i have code to redirect http://www.yoursite.com to https://www.yoursite.com

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.fancyblue.net/$1 [R,L]

but i need to modify the above code to redirect :smile:

http://mail.yoursite.com to https://mail.yoursite.com

Please help.

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} ^(.+\.)?fancyblue\.net$
RewriteRule ^(.*)$ https://%1fancyblue.net/$1 [R,L]

Untested, but I think this will do the trick. There’s a rewrite condition now that exists purely for the purpose of capturing the subdomain value, then we use that captured value (%1) in the rewrite.

afridy,

Jeff’s code will capture EVERY subdomain and force https. Since you only want to redirect the mail subdomain, specify mail.

RewriteEngine on RewriteCond %{SERVER_PORT} ^80$ RewriteCond %{HTTP_HOST} ^mail\.fancyblue\.net$ [NC] RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

The differrences are:

  1. Specify port 80 not any port containing 80 as digits in the port number.
  2. Specify mail.fancyblue.net using No Case.
  3. If both conditions are met, redirect the {REQUEST_URI} to the secure server without duplicating Apache variables for {HTTP_HOST} and {REQUEST_URI}; any query string will not be affected.

Regards,

DK

Thank you folks, Thanks so much. i have send the instruction to the client. will feedback if any problem he reported.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.