The correct name for the file is: .htaccess
Use mod_rewrite
to force HTTPS is not recommended for security reasons. read more on Redirectssl
It is recommended that you use Virtual Host for this... you can try this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://secure.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName secure.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
If even knowing this, still want to use mod_rewrite
:
1 = Remove the file .htaccess
root site: usually /var/www/html
2 = Create virtual hosts.
3 = Place a .htaccess
at the web root of every virtual host you want HTTPS.
File example .htaccess
:
Rewriteengine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
For other users who demand on the same issue, remember to check if your webserver is with the REWRITE module enabled, if not, you can enable with the command:
a2enmod rewrite
I hope I’ve helped!
@Danielomine on this topic you indicated he teaches how to activate https in just one domain, without affecting others. What I need is for https to work on meusite.com and shop.meusite.com without affecting others.
– Raizant
The correct name for the file is: . htaccess and not htacess, could check if your file is with the correct name?
– Allan Andrade
@Allanandrade I discovered the problem, my browser saved the cache with the previous htacess configuration and for some reason was not updating with the new htacess I set up in the subdomain... after I cleaned the cache worked normally...
– Raizant
on the link, follows the same logic.. just understand what has been done and apply to your case.
– Daniel Omine