I'm using the following to redirect http to https in my root directory htaccess file

<IfModule mod_rewrite.c>

  RewriteEngine On

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


But this seems not to work if I access directly sub directories (http://example.com/sub-directory/) unless I place this mod_rewrite in an htaccess file in all my sub drectories.

Anyone knows a better way to do this? Just in my root htaccess file?

Re: Forcing https with .htaccess 80 80


If you have access to the configuration file for the virtualhost then got the <Directory> and set AllowOverride to All:

<Directory /path/to/www/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted

Remember to adjust the options to your needs, the above example will show directory contents and so on... If you can choose the web server, then try Caddy, the community version is free and works good. It supports HTTP/2 and LetsEncrypt by default: https://caddyserver.com/

Re: Forcing https with .htaccess 80 80

Thanks, Cereal!

It's a shared hosting, so I don't have access to a server config file. Caddy looks interesting. Especially the HTTP/2.

Re: Forcing https with .htaccess 80 80

It's a shared hosting, , so I don't have access to a server config file

Okay, then you may want to ask to their support. The AllowOverride property is not always enabled for security and performance purposes, as Apache needs to scan the contents of each .htaccess along the folder tree and reset the rules accordingly.

virtualhost then got the <Directory>

oh my «got» o_o

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.