views:

61

answers:

1

I have an .htaccess file that mainly does 2 things. Force www on the domain and ask for login credentials (with .htpasswd).

If I now visit domain.com it will ask for a username and password. When I fill them in I get redirected to www.domain.com and then it asks me to log in again.

Is there any way to get the www redirection done before the login? I already tried putting the force www code on the top of the .htaccess file.

A: 

This is the code I have now... There is some more stuff in the .htaccess file, but these are the important parts

# Enable redirecting
    RewriteEngine on
    RewriteBase /

# Force www
    RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NC,L]

# Require login
    AuthUserFile /home/xxx/domains/xxx/public_html/.htpasswd
    AuthGroupFile /dev/null
    AuthName "xxx"
    AuthType Basic
    require valid-user
FinalFrag