dimanche 23 août 2020

Apache2 redirect https://example.com to https://www.example.com with vhosts

Folks,

I have apache server with vhosts.

For vhosts, I need to redirect http://*.example.com to https://*.example.com and it works as last block in the code.

Reg. the main server, I want to redirect https://example.com, http://example.com & http://www.example.com to https://www.example.com

http://example.com & http://www.example.com works fine but only https://example.com not directing.

Any ideas ?!

RewriteEngine On

# Redirect https://example.com to https://www.example.com #(NOT WORKING)
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]
#RewriteRule ^/(.*)$ https://www.example.com [R=301,L]


# Redirect http://example.com to https://www.example.com  #(WORKING)
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.%{HTTP_HOST}$1 [R=301,L]


# Redirects http://*.example.com to https://*.example.com #(WORKING)
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Thanks,




Aucun commentaire:

Enregistrer un commentaire