2

This may have been asked before but I can't find an answer.

I have recently purchased an SSL certificate and I need help setting up the .htaccess file.

I am using the MVC design pattern so every page goes though index.php

This is my current .htaccess configuration and all pages go through https

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

I have read that using https on the whole site adds overheads. Would it be possible to add rules for specific pages such as login/register/forgot password that would redirect to https instead of http?

1 Answer 1

2

To redirect specific pages to https:

RewriteEngine On
RewriteBase /

# specific pages to https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /(login|register|forgotPassword) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# all other pages to http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/(login|register|forgotPassword) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Sign up to request clarification or add additional context in comments.

4 Comments

Exactly what I wanted. If i needed to add more pages ,is it just add them to RewriteCond %{THE_REQUEST} /(login|register|forgotPassword) [NC]
Yes that's right, you can add more pages like that.
Last question. How would i add admin/news or something like that?
Use RewriteCond %{THE_REQUEST} /(login|register|forgotPassword|admin/news) [NC]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.