Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Redirect to https or RewriteRule |
|
Author |
|
Otomatic
Joined: 01 Sep 2011 Posts: 212 Location: Paris, France, EU
|
Posted: Fri 03 Dec '21 17:29 Post subject: Redirect to https or RewriteRule |
|
|
Hi,
In the thread : https://www.apachelounge.com/viewtopic.php?t=8790
you state that to perform an https redirect from a VirtualHost port 80, you must:
Code: | RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
Now, only locally, for development, in the VirtualHost port 80 to redirect to https, I put the Redirect directive below and it seems to work very well.
Code: | <VirtualHost *:80>
ServerName aviatechno
Redirect / https://aviatechno/
|
Is it better to use "your" RewriteRule and why?
Thank you. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 07 Dec '21 11:22 Post subject: |
|
|
Hi Otomatic,
it isn't better. It is just "copy and paste".
With the variable HTTP_HOST, I can copy-paste it into any vhost without ever worrying about the hostname. Also RewriteCond %{HTTPS} !=on would prevent any loops, if you paste it into the SSL vhost.
In short, it is a no brainer
Sure it could also be like
Code: |
<If "%{SERVER_PROTOCOL} != 'HTTPS'">
Redirect "/" "https://www.example.com/"
</If>
|
|
|
Back to top |
|
|
|
|
|
|