not redirecting to HTTPS from HTTP

Multi tool use
not redirecting to HTTPS from HTTP
I had tried every method of redirection i.e .htaccess
but none of the things work for me. as right now the .htaccess
file contains
.htaccess
.htaccess
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.booksoncall.in/$1 [R=301,L]
it work fine on my computer and the http is redirecting successfully to https version, but http version is still accessable on other pc and is not redirecting to https same is happening on mobile devices.
website --- booksoncall.in
are htaccess files authorized by your apache config ?
– ᴄʀᴏᴢᴇᴛ
Jul 3 at 8:02
Did you look at your logfiles?
– Patrick Mevzek
Jul 3 at 16:35
3 Answers
3
Give this a try if you want all requests to be redirected to https
RewriteEngine on
RewriteCond %{SERVER_NAME} = example.com [OR]
RewriteCond %{SERVER_NAME} = www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
This should be done in the Vhost file for port 80
Your
RewriteCond
syntax is wrong (you do not use =
). and also your setup will never work as multiple RewriteCond
are parsed as AND together so the server name can not be both strings at the same time. See httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond– Patrick Mevzek
Jul 3 at 14:26
RewriteCond
=
RewriteCond
Thanks for your input @PatrickMevzek - I forgot the [OR] statement in my example. Edited my answer.
– Sourcey86
Jul 4 at 7:03
for short version.
you dont need the server name.
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If you want to redirect all http request to https why not use
<VirtualHost 0.0.0.0:80>
ServerName www.example.com:80
Redirect permanent / https://www.example.com/
</VirtualHost>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Where exactly did you place this .htaccess file, is it in the web root of the domain? Why are you checking for port 80, there are other more common ways to check if the request was made via HTTPS or not.
– CBroe
Jul 3 at 8:00