Howard Lie
Howard Lie

Reputation: 108

.htaccess https only for homepage and http for other

I have a site eg: example.com with Lets Encrypt SSL installed. I want to force redirect all url from https to http but at the same time I want the homepage to be force redirect from http to https. Is such thing possible? Thank you.

My current .htaccess

<IfModule mod_rewrite.c>
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    RewriteRule .* index.php [F,L]
</IfModule>
Options +FollowSymlinks

RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} ^443$ [OR]

RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://clix2reach.com/$1 [R=301,L]

Upvotes: 2

Views: 1963

Answers (1)

Joe
Joe

Reputation: 4917

You can try using this:

RewriteEngine On
RewriteBase /

# Turn HTTPs on for homepage
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/index.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Turn HTTP on for everything but homepage
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

Change index.php depending on file name / extension.

Upvotes: 1

Related Questions