automatic redirection from http to https using .htaccess

Post Reply
User avatar
stani
Master Bludit
Posts: 79
Joined: Wed Oct 14, 2020 1:34 pm
Has thanked: 1 time

My .htaccess:

Code: Select all

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>

# Enable rewrite rules
RewriteEngine on

# all redirection HTTP -> HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# Base directory
#RewriteBase /

# Deny direct access to the next directories
RewriteRule ^bl-content/(databases|workspaces|pages|tmp)/.*$ - [R=404,L]

# All URL process by index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [PT,L]

</IfModule>
But there is no automatic redirection from http to https... :(

When I enter a URL with http, the site is with http - insecure. When I enter with https, it is with https.
There is no (automatic) redirection.
What's wrong?

----
Addition: Automatic redirection doesn't work with Firefox and Chrome, but it works with Edge. I do not understand this.
All three browsers are the latest, updated.
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

Why you think there should be such one?
If user's webserver (or hosting account) doesn't offer or is not configured to serve content through https, then installation might go wrong.
And even if there's https, checking it through mod rewrite doesn't guarantee it will work. It may only check if https is enabled on webserver.

If you can't find working rewrite rules for htaccess, do it with php.
There's also a redirect plugin handling the http to https switch.
User avatar
stani
Master Bludit
Posts: 79
Joined: Wed Oct 14, 2020 1:34 pm
Has thanked: 1 time

https is enabled on webserver.

What's the redirect plugin called?
User avatar
Jay
Master Bludit
Posts: 133
Joined: Mon Feb 11, 2019 8:41 pm

Is enabled on the sever YOU rent.
And you are talking about webapplication's default code.

One rule won't cover 100% use cases, not in IT.
There could be some good practices for users, like code droplets in wiki so they might test it on their own hosting environment.
As well as php enable/disable https switch in cms options, making use of php redirection. But that's more of a request/proposal and I haven't seen such one here, nor in github issues. And it still would need a bulletproof code. Once the switch won't work, user might not be able to login to backend anymore forcing him to edit bludit config files manually.
stani wrote: Sun Dec 06, 2020 5:05 pm What's the redirect plugin called?
Afair there's only one on bludit's plugin page.
User avatar
stani
Master Bludit
Posts: 79
Joined: Wed Oct 14, 2020 1:34 pm
Has thanked: 1 time

Simply uploading Redirects via FTP (to the /bl-plugins/ folder), will make the whole web inaccessible ...
User avatar
stani
Master Bludit
Posts: 79
Joined: Wed Oct 14, 2020 1:34 pm
Has thanked: 1 time

So everything back ... :D

My (above) created .htaccess works very well. I've re-uploaded and rewritten it on FTP, and redirects from all browsers work now great automatically. ;)
Post Reply