logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: .htaccess - Force www. on http and https
Author
ReeceN



Joined: 19 Sep 2015
Posts: 1
Location: Newcastle upon Tyne

PostPosted: Sat 19 Sep '15 18:00    Post subject: .htaccess - Force www. on http and https Reply with quote

Hi I would like to force www. on http and https so under the condition the following 2 things will happen:

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

Is this possible and does anyone know how to do it?

Thank you kindly,

Reece
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3057
Location: Hilversum, NL, EU

PostPosted: Sun 20 Sep '15 11:15    Post subject: Reply with quote

In a non-https vhost:

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

In a https vhost:

RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !=""
RewriteRule ^/(.*) https://www\.domain\.com/$1 [L,R=301]
Back to top


Reply to topic   Topic: .htaccess - Force www. on http and https View previous topic :: View next topic
Post new topic   Forum Index -> Apache