Enabling Free SSL with .htaccess

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Enabling Free SSL with .htaccess

Post by supanet » Thu Feb 07, 2019 7:45 pm

Hi can someone please give me a bit of guidance. :mrgreen:

I use Hostgator who offer a free SSL service but to enable it i need to alter my .htaccess file, it says to add this code:

Code: Select all

# Always use https for secure connections
# Replace 'www.example.com' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
First is this code right and if so where do i put it in the .htaccess file as some of the lines are similar to the code above like so:

Origonal file:

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]
Do i overwrite this or put the new code somewhere else in the file?

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 2132
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: Enabling Free SSL with .htaccess

Post by kinerity » Fri Feb 08, 2019 1:24 pm

It looks right. That would go at the top of your .htaccess file. There are a number of ways to force HTTPS. For example, this code works for me on my site.

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.layer-3.org/$1 [R,L]
Kailey Truscott - Community Team

User avatar
EA117
Registered User
Posts: 362
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Enabling Free SSL with .htaccess

Post by EA117 » Fri Feb 08, 2019 3:34 pm

supanet wrote: ↑
Thu Feb 07, 2019 7:45 pm
Do i overwrite this or put the new code somewhere else in the file?
Agreed with kinerity that you are adding these additional lines to your .htaccess; not replacing the existing condition and rule that were already present for app.php.

Putting the HTTPS condition and rule first (meaning "above" the existing app.php conditions and rules) probably makes the best sense, just as a very minor optimization to not execute the "-f" and/or "-d" tests an additional time whenever an HTTPS redirect is actually needed.

User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Re: Enabling Free SSL with .htaccess

Post by supanet » Fri Feb 08, 2019 5:08 pm

Thanks for all the help guys :D
Will give it a go over the weekend. 8-)

User avatar
Raul [ThE KuKa]
Style Customisations
Style Customisations
Posts: 5554
Joined: Mon Dec 08, 2003 9:24 pm
Location: Spain
Name: Raul Arroyo
Contact:

Re: Enabling Free SSL with .htaccess

Post by Raul [ThE KuKa] » Fri Feb 08, 2019 7:47 pm

About port 80... :roll:

Server settings - Server URL settings - Server port

For HTTP server port 80 it's OK, but for HTTPS server port 443

At least in my configuration, you can check this on your host. ;)

Best regards.
All unsolicited PMs will be ignored.
:warning: Knowledge Base | Documentation | Board rules | phpBB Styles Rules & Policies :warning:


If you like my styles, translations, etc. and want to show some appreciation, then feel free to Donate with Image
:flag_es: phpBB Spain - Online Since 2003 :heart:


🎨 phpBB Professional Premium Themes πŸ”₯

User avatar
janus_zonstraal
Registered User
Posts: 3156
Joined: Sat Aug 30, 2014 1:30 pm

Re: Enabling Free SSL with .htaccess

Post by janus_zonstraal » Fri Feb 08, 2019 7:51 pm

And in the example you want to redirect to the www version.
In the link under your account here you link to the non www version.
It is better to use always the same url.
Sorry! My English is bat ;) !!!

User avatar
3Di
Former Team Member
Posts: 13473
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Enabling Free SSL with .htaccess

Post by 3Di » Fri Feb 08, 2019 8:21 pm

And cookie secure ON btw.

Here's mine, in use on every site I worked on and never failed so far.
To put on the very top of the original file after <IfModule mod_rewrite.c>

This one redirects every url, it is a catch-all. With or without www etc..

Code: Select all

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Note: [R=301,L] means the redirect is permanent, instead [R,L] means is not.

The latter to be used first, IMO - Then change it to permanent once you know everything is alright.
That's for the sake of search engines' indexing.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity ΒΊ PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
__________________________________
πŸ‘¨β€πŸ« | Take a tour to | The Studio | πŸ‘¨β€πŸ«

User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Re: Enabling Free SSL with .htaccess

Post by supanet » Sat Feb 09, 2019 11:03 am

Thanks for all the info guys it was really helpful. :D

According to my C Panel everything seems to be working.
host.PNG
But even if i change the settings here to https they just revert back to http. :?
Cookie secure: is enabled.
ssl.PNG
what am i doing wrong?

User avatar
3Di
Former Team Member
Posts: 13473
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Enabling Free SSL with .htaccess

Post by 3Di » Sat Feb 09, 2019 7:03 pm

Post please your .htaccess file here within [code][/code] bbcode.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity ΒΊ PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
__________________________________
πŸ‘¨β€πŸ« | Take a tour to | The Studio | πŸ‘¨β€πŸ«

User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Re: Enabling Free SSL with .htaccess

Post by supanet » Sat Feb 09, 2019 8:23 pm

Ok here it is. :mrgreen:

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.tdudrivetime.com/$1 [R=301,L]
#
# Uncomment the statement below if URL rewriting doesn't
# work properly. If you installed phpBB in a subdirectory
# of your site, properly set the argument for the statement.
# e.g.: if your domain is test.com and you installed phpBB
# in http://www.test.com/phpBB/index.php you have to set
# the statement RewriteBase /phpBB/
#
#RewriteBase /

#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
# The following 3 lines will rewrite URLs passed through the front controller
# to not require app.php in the actual URL. In other words, a controller is
# by default accessed at /app.php/my/controller, but can also be accessed at
# /my/controller
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

#
# If symbolic links are not already being followed,
# uncomment the line below.
# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/
#
#Options +FollowSymLinks
</IfModule>

# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from
# module mod_authz_host to a new module called mod_access_compat (which may be
# disabled) and a new "Require" syntax has been introduced to mod_authz_host.
# We could just conditionally provide both versions, but unfortunately Apache
# does not explicitly tell us its version if the module mod_version is not
# available. In this case, we check for the availability of module
# mod_authz_core (which should be on 2.4 or higher only) as a best guess.
<IfModule mod_version.c>
	<IfVersion < 2.4>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfVersion>
	<IfVersion >= 2.4>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfVersion>
</IfModule>
<IfModule !mod_version.c>
	<IfModule !mod_authz_core.c>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfModule>
	<IfModule mod_authz_core.c>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfModule>
</IfModule>

User avatar
3Di
Former Team Member
Posts: 13473
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Enabling Free SSL with .htaccess

Post by 3Di » Sat Feb 09, 2019 8:55 pm

Change the first 4 lines

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.tdudrivetime.com/$1 [R=301,L]
to

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
and set Server protocol to https:// - change the cookie's name as well (and set it to secure).

port 80 is ok for now, if this fails change it to 443 (only if fails).

Only 2 hours ago I did use this approach also for another user, btw.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity ΒΊ PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
__________________________________
πŸ‘¨β€πŸ« | Take a tour to | The Studio | πŸ‘¨β€πŸ«

User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Re: Enabling Free SSL with .htaccess

Post by supanet » Sun Feb 10, 2019 10:35 am

3Di wrote: ↑
Sat Feb 09, 2019 8:55 pm
Change the first 4 lines

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.tdudrivetime.com/$1 [R=301,L]
to

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
and set Server protocol to https:// - change the cookie's name as well (and set it to secure).

port 80 is ok for now, if this fails change it to 443 (only if fails).

Only 2 hours ago I did use this approach also for another user, btw.
Hi, thanks for taking the time to help with this.

Done everything you say but Server protocol: still reverts back to http:// after i Purge the cache or refresh. :(

Doesn't work if i change port to 443 ether. :(

This is where i got the settings from Hostgator: https://support.hostgator.com/articles/ ... r-free-ssl (it says port 80)
free ssl.PNG

User avatar
Mick
Support Team Member
Support Team Member
Posts: 20850
Joined: Fri Aug 29, 2008 9:49 am
Location: Watching cricket - probably.

Re: Enabling Free SSL with .htaccess

Post by Mick » Sun Feb 10, 2019 11:49 am

If it's the board in your signature it seems to be working ok for me. If you go in with http it changes to https.
"The more connected we get the more alone we become" - Kyle Broflovski

There are no β€˜threads’ in phpBB, they are topics.

User avatar
supanet
Registered User
Posts: 234
Joined: Sat Dec 15, 2012 4:20 pm
Location: UK
Contact:

Re: Enabling Free SSL with .htaccess

Post by supanet » Sun Feb 10, 2019 11:56 am

Mick wrote: ↑
Sun Feb 10, 2019 11:49 am
If it's the board in your signature it seems to be working ok for me. If you go in with http it changes to https.
Yes works ok just can't get Server protocol: to display https:// :?

User avatar
Raul [ThE KuKa]
Style Customisations
Style Customisations
Posts: 5554
Joined: Mon Dec 08, 2003 9:24 pm
Location: Spain
Name: Raul Arroyo
Contact:

Re: Enabling Free SSL with .htaccess

Post by Raul [ThE KuKa] » Sun Feb 10, 2019 2:43 pm

Not "green" button...
Mixe (index):260 Mixed Content: The page at 'https://tdudrivetime.com/' was loaded over HTTPS, but requested an insecure image 'http://s06.flagcounter.com/count/WPZR/b ... 1/flags_1/'. This content should also be served over HTTPS.
You should change all images and links to HTTPS for no "mixe" HTTP with HTTPS
All unsolicited PMs will be ignored.
:warning: Knowledge Base | Documentation | Board rules | phpBB Styles Rules & Policies :warning:


If you like my styles, translations, etc. and want to show some appreciation, then feel free to Donate with Image
:flag_es: phpBB Spain - Online Since 2003 :heart:


🎨 phpBB Professional Premium Themes πŸ”₯

Post Reply

Return to β€œ[3.2.x] Support Forum”

Who is online

Users browsing this forum: Brf, EA117 and 33 guests