Redirect to www when using SSL
Have a strange problem. Using certificate for a few domains, but one of them has an issue with the Apache configuration.
This is the apache configuration for the virtual host:````
ServerName www.domain.tld
ServerAlias domain.tld
RewriteEngine on
RewriteCond %{HTTPHOST} !^$ [OR]
RewriteCond %{HTTPHOST} !^www. [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTPHOST}%{REQUESTURI} [L,R=301]
ServerName www.domain.tld
ServerAlias domain.tld
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.domain.tld%{REQUEST_URI} [R=301,L]
DocumentRoot /var/www/domain.tld/public_html/
ErrorLog /var/www/domain.tld/logs/error.log
CustomLog /var/www/domain.tld/logs/access.log combined
SSLEngine on
SSLCertificateChainFile /etc/ssl/AlphaSSLRoot-Bundle.crt
SSLCertificateFile /etc/ssl/localcerts/www.domain.tld.crt
SSLCertificateKeyFile /etc/ssl/localcerts/www.domain.tld.key
````
But
Any help on this is appreciated! Thanks!
6 Replies
RewriteCond %{HTTP_HOST} !^$ [OR]
I'm no htaccess expert, but I've always used that line as part of the conditions when forcing 'www'.
What exactly is that row doing? I tried to put it first (after RewriteEngine on) but then I'm getting "Page is redirecting the wrong way" and it stops loading. Any other suggestions?
I'm not sure what it does, but I've always needed it for redirecting to 'www'.
James
http://www.askapache.com/category/htaccess/
I have had
about 1/2 way down that page is this
(added that specific link)
Thanks for the link, but cannot find what I'm looking for. The force www is working fine for the Non-SSL (port 80) part, the problem is that https:// won't redirect as it should.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
#Second Force HTTPS via redirect/rewrite
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
I think if you use mine as a template you will get working as you desire…. as yours stands apache has no way to know that '
take note of the "."[dot]
try this code for your line that looks similiar:(the last line)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]