@jimr1 found this method on the internet please tell me if its gonna help??
Install the Apache server.
apt-get update
apt-get install apache2
Enable the required Apache modules.
a2enmod ssl
a2enmod rewrite
Edit the Apache configuration file for the desired website.
vi /etc/apache2/sites-enabled/000-default.conf
Add the following lines to this configuration file.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
Here is the file, before our configuration.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Here is the file, after our configuration.
<VirtualHost :80>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.) https://%{SERVER_NAME}/$1 [R=301,L]
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Restart the Apache service.
service apache2 restart
In our example, the Apache server will redirect all HTTP requests to HTTPS.
From a remote Linux computer, try to perform an HTTP access.
curl -I http://www.gameking.tips
Here is the command output.
HTTP/1.1 301 Moved Permanently
Date: Tue, 12 Jan 2021 19:27:59 GMT
Server: Apache/2.4.41 (Ubuntu)
Location: https://www.gameking.tips/
Content-Type: text/html; charset=iso-8859-1
In our example, if a user tries to access the HTTP version of any page, he will be redirected to the HTTPS version of the same page.
Make sure that you have an HTTPS website configured on the Apache server or the connection will be lost.
As an example, here is an Apache configuration file with HTTP and HTTPS enabled.
<VirtualHost :80>
ServerName www.gameking.tips
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.) https://%{SERVER_NAME}/$1 [R=301,L]
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<VirtualHost *:443>
ServerName www.gameking.tips
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/certificate/apache-certificate.crt
SSLCertificateKeyFile /etc/apache2/certificate/apache.key
Congratulations! You successfully configured the HTTP to HTTPS redirection on the Apache server.