Darcey
Darcey

Reputation: 1987

htaccess to redirect all trafic from http to https but to also redirect to index.php which is hidden once on https

I am looking for a .htaccess file which can do the following, I've managed to get each function to work individually but not together.

Requirement no 1: All HTTP traffic is redirected to HTTPS

Requirement no 2: All HTTPS URLs are directed to index.php?url_params=

I either end up with an endless loop on the request_uri or I end up with server error:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} off
#RewriteCond %{HTTP:X-Forwarded-Proto} = http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?url_path=$1 [L,NC,QSA]

So if someone was to type in "http://www.example.com/page1" it would redirect to "https://www.example.com/page1" and then "https://www.example.com/page1" is sent to index.php with page1 sent as a url param

Thanks

D

Upvotes: 1

Views: 64

Answers (1)

anubhava
anubhava

Reputation: 785058

Try these rules:

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url_path=$1 [L,QSA]

Clear your browser cache before testing this change.

Upvotes: 1

Related Questions