Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jun 2017
    Posts
    14
    Thanks
    8
    Thanked 0 Times in 0 Posts

    .htaccess to redirect non-www to www, http to https, then do http authentication

    Hello all,

    I am trying to write a .htaccess file that does the following:

    - redirects example.com to www.example.com
    - redirects http to https
    - I'd like it to do both corrections above in one redirect, not two
    - I'd like it to do all those corrections first, then do http/401 authentication popup

    I'm not sure if the last item is possible (redirecting before authentication). However I know the other 3 are, just my code isn't working well yet. Here is what I have so far.

    Code:
    RewriteEngine On
    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
    
    AuthType Basic
    AuthUserFile /home/exampleuser/example.com/.htpasswd
    AuthName "Secure Area"
    require valid-user
    Thanks in advance for your help.
    Last edited by AdmiralAdama; Feb 13th, 2018 at 09:28 PM. Reason: removed automatic link conversion


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •