Command Line

Apache / .htaccess Redirects

Redirect from http to https via Apache config

SSH into your server and go to

cd ../etc/apache2/sites-available/

This depends on how your VHOST is configured.

Edit the httpd.conf file, or in my case the httpd.conf is called yourdomain.com

vim yourdomain.com

Between: <VirtualHost>…</VirtualHost> at the below

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME} [R,L]

Or replace line 3 above with the below to allow url/path/ and R=301 to make it a 301

RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Then “check apache” & “restart apache” with the below commands respectively:

apachectl -t
/etc/init.d/apache2 reload

This restart command may vary depending on your OS.

If you do not have root access, you can add the above in a .htaccess file on the root of you domain via ftp or file manager.