0

I have the following .htaccess file:

RewriteEngine On

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


RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

AuthType Basic
AuthName "Access to /www.mydomain.de"
AuthUserFile /myfolder/homepages/10/d563344564/htpasswd
Require user admin

If I reach mydomain.de the system asks me the password twice (I guess the first for mydomain.de and the second for www.mydomain.de). But this happens also when in some images are loaded (the src attribute contains the link with www, but probably it is already changed because of .htaccess). Which way can I follow to have just one password request at the beginning?

db92
  • 183
  • 3
  • 16

1 Answers1

1

You might enclose the authentication configuration in an If directive and check for the host

<If %{HTTP_HOST} == "www.example.com">
    AuthType Basic
    ...
</If>

Another approach, if you have access to the main config files, split into two virtual hosts and do the redirect as in Simple Redirection. This way you can put the authentication part into the appropriate virtual host section.

Finally, never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198