SOLVED: Force HTTPS for sub-directory?

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
Post Reply
eriklauritsen
Registered User
Posts: 4
Joined: Fri Nov 08, 2019 2:32 am

SOLVED: Force HTTPS for sub-directory?

Post by eriklauritsen » Fri Nov 08, 2019 2:38 am

Hi,

I am struggling to force https for a new phpbb installation. The installation is in a subdirectory. So http://example.com/forum/ needs to redirect to https://example.com/forum/, how do I do that?

I have tried with the following for .htaccess, but it is not working working:

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Last edited by eriklauritsen on Fri Nov 08, 2019 11:16 pm, edited 1 time in total.

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3356
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Force HTTPS for sub-directory?

Post by thecoalman » Fri Nov 08, 2019 12:21 pm

If you are utilizing the existing htaccess file provided with phpBB in http://example.com/forum/ and also have rules in .htacces file located in http://example.com/ they can take precedent so you may want to check if there is conflict.


In any event need more information such as where you are putting this rule.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison

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

Re: Force HTTPS for sub-directory?

Post by EA117 » Fri Nov 08, 2019 1:10 pm

Also try adding [L,R=301] to the end of the RewriteRule line:

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirecting the web browser to make a new connection over HTTPS requires the hard redirect (R), and there is no need to continue processing other rules when the conditions for this RewriteRule have been satisfied (L). The remaining rules in the .htaccess will still end up being applied, once the web browser connects using the desired HTTPS URL.

eriklauritsen
Registered User
Posts: 4
Joined: Fri Nov 08, 2019 2:32 am

Re: Force HTTPS for sub-directory?

Post by eriklauritsen » Fri Nov 08, 2019 11:06 pm

thecoalman wrote:
Fri Nov 08, 2019 12:21 pm
If you are utilizing the existing htaccess file provided with phpBB in http://example.com/forum/ and also have rules in .htacces file located in http://example.com/ they can take precedent so you may want to check if there is conflict.

In any event need more information such as where you are putting this rule.
I am utilizing the htaccess file provided with phpBB and I don't have a htaccess in the root i.e. http://example.com.

If I use the following I get the "to many redirect errors":

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

eriklauritsen
Registered User
Posts: 4
Joined: Fri Nov 08, 2019 2:32 am

Re: Force HTTPS for sub-directory?

Post by eriklauritsen » Fri Nov 08, 2019 11:16 pm

I got it working now.

I put the following in htacess in the root folder of example.com:

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{REQUEST_URI} forum
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
</IfModule>
And then utilized the htaccess from phpBB in the subfolder /forum/

Code: Select all

RewriteBase /forum/
That got everything working.

eriklauritsen
Registered User
Posts: 4
Joined: Fri Nov 08, 2019 2:32 am

Re: SOLVED: Force HTTPS for sub-directory?

Post by eriklauritsen » Sat Nov 09, 2019 12:11 am

Actually the above didn't work either (got cheated by the browser).

I had to put the following in the root in htaccess:

Code: Select all

RewriteEngine On

# If we receive a forwarded http request from a proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]

# ...or just a plain old http request directly from the client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on

# Redirect to https version
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And then comment out completely the htaccess from phpBB. Now it works.

Post Reply

Return to “[3.2.x] Support Forum”