Author |
|
compareandchoose
Joined: 25 Dec 2015 Posts: 3 Location: brisbane
|
Posted: Fri 25 Dec '15 23:30 Post subject: Forcing http to https and none www to www |
|
|
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
|
Posted: Sat 26 Dec '15 10:34 Post subject: |
|
|
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
|
Posted: Sun 27 Dec '15 1:36 Post subject: thanks but still confused |
|
|
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
|
Posted: Sun 27 Dec '15 16:20 Post subject: |
|
|
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
|
Posted: Sat 02 Jan '16 14:01 Post subject: Cant seem to get it working |
|
|
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
|
Posted: Sat 02 Jan '16 22:26 Post subject: |
|
|
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 |
|