1 Replies - 803 Views - Last Post: 11 June 2017 - 07:01 AM

#1 O'Niel   User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 431
  • Joined: 13-September 15

Persisting HTTPS in .htaccess

Posted 11 June 2017 - 04:04 AM


In my .htaccess file I use this code currently to persist HTTPS.
So http:// requests get redirected to https://

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

It is partly working, http://website.com gets redirected to https://website.com.
when I try to acces http://website.com/contact or http://website.com/about without
being on the website in the first place, I get redirected to http://website.com/index.php

I need to be on the website first in order to be able to visit /page /contact /about,
I can't access it directly from the URL-bar without being on the website.

This problem occurs on this website: http://ndvibes.com
Try to click https://ndvibes.com/about without being on the website,
you get redirected to index.php

A better way to persist HTTPS via .htaccess?


This post has been edited by O'Niel: 11 June 2017 - 05:16 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Persisting HTTPS in .htaccess

#2 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,140
  • Joined: 10-May 07

Re: Persisting HTTPS in .htaccess

Posted 11 June 2017 - 07:01 AM

If this were me, I would force a 301 in the vhost config. This reduces traffic as their entry point is redirected, & then you don't need to redirect every access after. But be mindful of your links when writing code.

<VirtualHost [ipaddress]:80>
	ServerName example.com
	Redirect / https://example.com

<VirtualHost [ipaddress]:443>
	ServerName example.com

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1