Apache Force SSL on vhost

Edit your htaccess (or server conf file) to look like this one :

  1. <Files *.ini>
  2. Order Allow,Deny
  3. Deny from all
  4. </Files>
  5.  
  6. RewriteEngine on
  7. RewriteBase /
  8.  
  9. RewriteCond %{SERVER_PORT} !443
  10. RewriteRule ^(.*)?$ https://%{SERVER_NAME}$1 [L,R]

For thoses of you who don't know about RewriteCond?, the first one check the server port used to connect. If it's not 443 (default HTTPS port), it redirects all request to the same https vhost and URI.

Reference

  • https://trac.usvn.info/wiki/Documentation/HTTPSAccess
  • Trackback URL for this post:

    http://www.2030.tk/trackback/13

    Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Use <fn>...</fn> to insert automatically numbered footnotes.
    • You can use the <go> tags just like the <a> for nicer urls.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
    • Web page addresses and e-mail addresses turn into links automatically.
    • Lines and paragraphs break automatically.

    More information about formatting options

    CAPTCHA
    This question is for testing whether you are a human visitor and to prevent automated spam submissions.
    Image CAPTCHA
    Copy the characters (respecting upper/lower case) from the image.