0

I've installed ssl on both my pure-domain and www subdomain. They works as well. I need to redirect all http protocol requests to https. Here is the config of the apache:

<VirtualHost *:80>

    ServerName lamtakam.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/myweb

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =lamtakam.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<VirtualHost *:80>
    ServerName www.lamtakam.com
    DocumentRoot /var/www/html/myweb

RewriteEngine on
RewriteCond %{SERVER_NAME} =lamtakam.com [OR]
RewriteCond %{SERVER_NAME} =www.lamtakam.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

<Directory /var/www/html/myweb>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Any idea how can I make that redirection? Currently some cases works as expected and that redirection happens. The only domain that redirection doesn't happen for it is:


Noted that this doesn't work: (however not sure if I place it correctly in the configuration)

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?lamtakam\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [END,NE,R=permanent]
2

This used to work but is not recommended as of somewhere in 2010 even. So don't use this:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?lamtakam\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [END,NE,R=permanent]

Those would have been added to .htaccess.

You should be using this (from the same link):

<VirtualHost *:80>
    ServerName www.examples.com
    Redirect / https://www.examples.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.examples.com
    # ... SSL 
</VirtualHost>
  • Still the website is loaded on http protocol lamtakam.com/questions (not secure) – Martin AJ Aug 22 '18 at 13:30
  • I don't see a <VirtualHost *:443> in your question. Is there one? Cuz if there was not before you added mine... you need a lot more lines in that VirtualHost. Your in the question is not for SSL ... – Rinzwind Aug 22 '18 at 13:34
  • well no, I don't have <VirtualHost *:443>. Since I don't know what should I write inside it (instead of # ... SSL ). I just added Redirect / https://lamtakam.com/ in the first <VirtualHost *:80>, and also I added Redirect / https://www.lamtakam.com/ in the second <VirtualHost *:80> – Martin AJ Aug 22 '18 at 13:38
  • Also I guess no need to <VirtualHost *:443> in the apache configuration. You know, I use letsencrypt and it will add all needed things automatically – Martin AJ Aug 22 '18 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.