Home How do i force redirect to secure domain with htaccess
Reply: 0

How do i force redirect to secure domain with htaccess

user1524
1#
user1524 Published in April 24, 2018, 6:37 am

This question already has an answer here:

  • Force SSL/https using .htaccess and mod_rewrite 9 answers

When a request comes to my website from insecure http://, i want it to get redirected to https://.

My root directory has both html and php files in it. Based on request path i will decide whether to serve HTML or PHP file.

Below is my existing .htaccess file.

RewriteEngine On
RewriteRule "^(news_[^.]+|faq|terms|get).*" "$1.php" [NC,L]

the above configuration works fine for serving files from both secure and insecure domains.

But when i try to force SSL by changing the above configuration

RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# # Redirect to https version
RewriteRule ^get$ "https://example.com/get.php" [L]
RewriteRule ^faq$ "https://example.com/faq.php" [L]
RewriteRule ^terms$ "https://example.com/terms.php" [L]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It is forcing SSL for all the html pages that is being served from the directory. But the /get, /faq , /terms are getting a request timeout.

How do i fix it ? Where am i doing it wrong ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335753 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO