Redirect non-www ssl traffic to www ssl (apache)

Posted by The NinjaSysadmin on Server Fault See other posts from Server Fault or by The NinjaSysadmin
Published on 2011-01-11T10:48:33Z Indexed on 2011/01/11 10:55 UTC
Read the original article Hit count: 186

Filed under:
|
|

Hello,

I'm attempting to get a redirect which is failing, and for some reason I can't think today. I have a vHost file within HTTPD that listens on standard port 80 and port 443. I'm attempting to redirect https://domain.com/(.*) to https://www.domain.com/$1 so that the URL remains intact.

My config is as follows:

ServerName www.domain.com
ServerAlias tempdomain.testdomain.co.uk
ServerAlias domain.com

My rerwrite rule I'm using is.

RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ https://www.domain.com$1 [R=301,L]

I've also tried removing the . and $ but nothing.. When I visit the url https://domain.com/secure.page?action=comp it doesn't redirect to https://www.domain.com/secure.page?action=comp I do also have other SSL pages, the above was just an example..

Can anyone point out my stupidity.

© Server Fault or respective owner

Related posts about linux

Related posts about apache