logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in  RSS Apache Lounge  


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.


Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Redirect to https or RewriteRule
Author
Otomatic



Joined: 01 Sep 2011
Posts: 86
Location: Paris, France, EU

PostPosted: Fri 03 Dec '21 17:29    Post subject: Redirect to https or RewriteRule Reply with quote

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: 7128
Location: Germany, Next to Hamburg

PostPosted: Tue 07 Dec '21 11:22    Post subject: Reply with quote

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 Wink


Sure it could also be like

Code:

<If "%{SERVER_PROTOCOL} != 'HTTPS'">
    Redirect "/" "https://www.example.com/"
</If>
Back to top


Reply to topic   Topic: Redirect to https or RewriteRule View previous topic :: View next topic
Post new topic   Forum Index -> Apache