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: Forcing http to https and none www to www
Author
compareandchoose



Joined: 25 Dec 2015
Posts: 3
Location: brisbane

PostPosted: Fri 25 Dec '15 23:30    Post subject: Forcing http to https and none www to www Reply with quote

Hi All

I have managed to ensure everything is good to go on https for my website

what I am looking to do with my htacess file is now force it to https and also ensure that if anyone type in our domain without the www that it also put www on

I have one question which is would the below work. if so would I need to flag to on or off

RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !=www.example.com.au
RewriteRule ^ https://www.example.com.au%{REQUEST_URI} [L,R]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7407
Location: EU, Germany, Next to Hamburg

PostPosted: Sat 26 Dec '15 10:34    Post subject: Reply with quote

The flags are

L for last rule. That is important for a redirect.
R is the redirect.


I suggest to use

[L,R=301]

To have a 301 redirect instead of a 302.
Back to top
compareandchoose



Joined: 25 Dec 2015
Posts: 3
Location: brisbane

PostPosted: Sun 27 Dec '15 1:36    Post subject: thanks but still confused Reply with quote

So would I use the on or off flag

RewriteCond %{HTTPS} =on [OR]
RewriteCond %{HTTP_HOST} !=www.example.com.au
RewriteRule ^ https://www.example.com.au%{REQUEST_URI} [L,R=301]


or

RewriteCond %{HTTPS} =off [OR]
RewriteCond %{HTTP_HOST} !=www.example.com.au
RewriteRule ^ https://www.example.com.au%{REQUEST_URI} [L,R=301]
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7407
Location: EU, Germany, Next to Hamburg

PostPosted: Sun 27 Dec '15 16:20    Post subject: Reply with quote

It would be much easier if you do the SSL forcing in the port 80 vhost with off and put the force WWW rule into the port 443 vhost.

If you can't edit the apache config use the rule with the off.
Back to top
compareandchoose



Joined: 25 Dec 2015
Posts: 3
Location: brisbane

PostPosted: Sat 02 Jan '16 14:01    Post subject: Cant seem to get it working Reply with quote

We cannot seem to get this working as some how when we put in URL/page-url it just defaults to the home page or even our search engine results in google just redirect back to out https home page when we really want it to go to URL/page-url on https

Here is our full htaccess file to see if anyone can spot where the problem is. I have been working solid on this for 2 days and cannot figure it out, its either a wordpress setting or something in the htaccess file that maybe wordpress has set, what I have notices is two if mod_rewrite.c statements but I am none the wiser


Admin moved full htaccess to: http://apaste.info/D8O
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7407
Location: EU, Germany, Next to Hamburg

PostPosted: Sat 02 Jan '16 22:26    Post subject: Reply with quote

Wow that is a very long list of rewrite rules and some rules override other rules. I'm not sure which rules wins...
Also the deflate rule a double.

To force SSL for any of your vhosts.

Code:

RewriteEngine On
# force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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


Make sure that in your config is only one RewriteEngine On and only one RewriteBase
Back to top


Reply to topic   Topic: Forcing http to https and none www to www View previous topic :: View next topic
Post new topic   Forum Index -> Apache