Hey, I recently installed Lets Encrypt SSL, its successful however it wont redirect whenever its on http. So how to redirect all to https??
Here method I already tried but it seems wont working: 1 .htaccess
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
< ?php function redirectTohttps() { if($_SERVER[‘HTTPS’]!=”on”) { $redirect= “https://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’]; header(“Location:$redirect”); } } ?>
< meta http-equiv=“Refresh” content=“0;URL=https://www.example.com” />
Note*: This method works however it cause infinite loop and crash the server.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey. letsencrypt’s auto option should do this for you so I am guessing it’s possible you do not have the rewrite module enabled. This can be fixed by running sudo a2enmod rewrite; sudo service apache2 restart
I have a fresh LAMP server I ran letsencrypt on the other day with a pretty standard configuration and redirects are working as expected so I’ll just share that config with you.
letsencrypt creates two configuration files if you opt for the redirect http to https option. The first is for the non-https (port 80) host.
<VirtualHost *:80>
ServerName sub.example.org
DocumentRoot /var/www/sub
DirectoryIndex index.php
<Directory /var/www/sub/>
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
RewriteEngine on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
Then the file created for the SSL (port 443) host:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName sub.example.org
DocumentRoot /var/www/sub
DirectoryIndex index.php
<Directory /var/www/sub/>
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
SSLCertificateFile /etc/letsencrypt/live/sub.example.org/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sub.example.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/sub.example.org/chain.pem
</VirtualHost>
</IfModule>
Nginx:
server {
listen 80;
server_name .example.com;
location / {
rewrite ^(.*) https://example.com$request_uri;
}
}
server {
listen {IP}:443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/certs/example.com/example_com.crt;
ssl_certificate_key /etc/ssl/certs/example.com/example.com.key;
root "/var/www/example.com";
error_log "/var/log/nginx/error.example.com.log";
location / {
try_files $uri $uri/ index.html;
}
}
I have installed SSL manually on my website and configured apache2 virtual host. installation is successful but I am facing issue with redirection. What is it doing, it is combining the .com extention with the directive selected. Can anyone please help me troubleshoot this issue.
Code goes here.
<VirtualHost *:443> ServerAdmin admin@pinnacledu.com DocumentRoot /var/www/html ServerName pinnacledu.com SSLEngine on SSLCertificateFile /etc/ssl/certs/pinnacledu_com.crt SSLCertificatekeyFile /etc/ssl/certs/pinnacledu.com.key SSLCertificateChainFile /etc/ssl/certs/pinnacledu_com.ca-bundle <Directory /var/www/html> AllowOverride All Options FollowSymlinks </Directory> </VirtualHost>
<VirtualHost *:80> ServerName pinnacledu.com Redirect / https://pinnacledu.com/ </VirtualHost>
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
This comment has been deleted
Just add this into apache site config and change the domain.
It works for me too, thank you so much @KorencSoft !
Gracias funciono.
It works for me, thanks!
If you can, use the virtual host in terminal(command line) of your server, and change “Redirect Permanent” to the https version… and then it will be redirected with entered as http… or www… etc