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

#1 O'Niel  Icon User is offline

  • D.I.C Regular

Reputation: 14
  • View blog
  • Posts: 394
  • Joined: 13-September 15

Persisting HTTPS in .htaccess

Posted 11 June 2017 - 04:04 AM

Hi

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.
However,
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?

Thanks!

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  Icon User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6595
  • View blog
  • Posts: 30,789
  • 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>

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


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1