Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect https:// to https://www

Tags:

https

apache2

I know how to redirect from:

http://domain.com to https://www.domain.com

and

http://www.domain.com to https://www.domain.com

but not how to redirect from:

https://domain.com to https://www.domain.com

I am using on the virtual server for port 80 : (this works fine)

RedirectMatch 301 ^/$ https://www.domain.com
RedirectMatch 301 ^(.*)$ https://www.domain.com
RedirectMatch 301 ^http://domain.com/$ https://www.domain.com

I tried using on the virtual server port 443, but it does not work.

Redirectmatch 301 ^https://domain.com/ https://www.domain.com
like image 655
gringoLoco007 Avatar asked Feb 25 '11 15:02

gringoLoco007


People also ask

How do I redirect a website to www?

Under Type, select the Permanent (301) option. On https?://, enter the domain you want to redirect. Leave the path section (/) empty. In the Redirects to field, type in your website's www URL.

Can I forward a HTTPS to another HTTPS?

You will need to have a valid SSL certificate for https://www.example.com as the hostname is encrypted inside the HTTP header so your server won't know to redirect until it's decrypted. After that it should redirect as it would a normal HTTP request.


1 Answers

You would need to have a certificate that matches domain.com, as well as your standard www.domain.com certificate, since you can't redirect until after an SSL channel has been established.

Most people wouldn't think it was worth the expense of obtaining two certificates for each domain, just to achieve a redirect. A Wildcard certificate wouldn't help here (I believe), since I think all domains covered by a wildcard cert have to be at the same level (e.g. *.domain.com would be valid for www.domain.com and www2.domain.com, but not for just domain.com)

like image 88
Damien_The_Unbeliever Avatar answered Nov 22 '22 22:11

Damien_The_Unbeliever