Link to home
Start Free TrialLog in
Avatar of djs120
djs120

asked on

Protected dir asks for user/pwd twice if the ending slash is missing in URL

I am using .htaccess/.htpasswd to secure a directory (ex: http://www.domain.org/preview/) but notice that the username/password entry screen works differently in two different scenarios:

1. If I use the URL: http://www.domain.org/preview/, it only asks for username/password ONCE, which is what I want it to do.
2. But if I use the URL : http://www.domain.org/preview (notice no ending slash) it asks for the username/password TWICE and after entering it the second time it successfully loads the page but it redirects to http://domain.org/preview/ (notice www. is now missing).

Why is this happening?  I am afraid users are getting the username/pwd screen twice and might say 'forget this' and not look at the site.

Any thoughts?

Thanks.
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

It is because on your server config file ServerName directive is not set correctly for you VirtualHost:
It should be:
<VirtualServer www.domain.org:80>
ServerName www.domain.org
#some other directives
.......
</VirtualServer>


Avatar of djs120
djs120

ASKER

Just FYI, our webserver hosts 5 different websites, so we use virutal hosts, and in my VHost.conf file I have the following:

<VirtualHost 123.123.123.123>
        ServerName domain.org
        ServerAlias www.domain.org
        ServerAlias ...... (and then I have lots of other alias' for this domain)
        #some other directives

So you are saying I should change the "ServerName domain.org" to "ServerName www.domain.org"?  It seems like our hosting company has all 5 of our websites that are hosted on this server set up the same wway with ServerName missing the "www.".  Should this be changed for all domains and will it have adverse affects on anything?  If we change that to add the "www." and then try to browse to "httP://domain.org" will it still work?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of ramazanyich
ramazanyich
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djs120

ASKER

Thanks for the help, I emailed my hosting company to make these changes, so I'll wait to hear back from them.

I'm increasing point value for this question because you're putting more effort in than 125 points worth (in my opinion).

Thanks.
Thanks, hope my suggestions will work.
Avatar of djs120

ASKER

You were right, I did step # 1 above:
1. you set ServerName www.domain.org and
ServerAlias domain.org

My hosting company actual created a VHost_custom.conf file which is loaded before VHost.conf, since VHost.conf is automatically re-generated each time I create a new account on our dedicated box, and it worked out perfectly.

Thanks!