I know there are plenty of tutorials online and posts here about redirecting HTTP to HTTPS using .htaccess. However, my problem is regarding the URL which will be changed during redirection.
Apache2 should forward "http://localhost/~user/secure_secrets" to https://localhost/~user/secure_secrets". I have apache_2 installed and have public_html being served from users' home directories using userdir module. Now, inside public_html, I have a folder called "secure_secrets", which the URL refers to. For the redirection, I have set .htaccess thus:
# Enable rewrite
RewriteEngine on
# Check if connection is not already HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^/?secure_secrets/(.*) https://localhost/~user/secure_secrets/$1 [R,L]
But it doesn't work. When I type the HTTP url in the browser, it says 404 not found. I think I made a mistake in specifying the HTTP URL in the rewrite URL, but I cannot understand where.
As extra information, my other configurations are:
in /etc/apache2/sites-available/000-default.conf:
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
and, /etc/apache2/mods-enabled/userdir.conf:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
I hope someone can help me with this? Thanks in advance!