0

Please could anyone help me in my hour of need? :) I have been working on a landing page that's been set up for corporations and their employees. Anyway the gist is, the page is only available via login which is provided via promotional materials.

So I have index.php and it's only available via login using .htpasswd and .htaccess

.htaccess reads

AuthUserFile /my/path/to/.htpasswd
AuthName "Company Name"
AuthType Basic

However, up until now we have had a holding page, index.html which we have now removed so index.php displays when someone calls up http://mydomainname.com/ or http://www.mydomainname.com

If I visit http://mydomainname.com/ or http://www.mydomainname.com, all I get is a 401 Authorisation required page.

But if I visit the http://mydomainname.com/index.php the right page appears.

I have asked the hosting company and all they do is remove the .htaccess file which defeats the object. Theys ay I had an error in my .htaccess file, but it worked ok when there was an index.html page (which was the holding page).

debonator
  • 85
  • 2
  • 13

2 Answers2

0

If you just need to remove the www's in the url (which I think is what you're after), try the following in your htaccess;

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

This should work as long as your servers set up to handle either url. E.g. with apache, the ServerAlias would be like so ServerAlias *mydomain.com the * allows for both www's and no www's

EDIT

If I look at one of my own htaccess/htpasswd files I have the following, check yours is similar;

htaccess;

AuthType Basic
AuthName "Hidden Page"
AuthUserFile /var/www/mysite.com/hiddendir/.htpasswd
Require valid-user

htpasswd;

USER:encryptedpasswordstring
Novocaine
  • 4,692
  • 4
  • 44
  • 66
  • OK My question is how can I get domainname.com or www.domainname.com to redirect to this password-protected page at http://domainname.com/index.php or http://www.domainname.com/index.php. I am open to suggestions. – debonator Nov 05 '14 at 14:44
  • `domain.com` will automatically show content from `domain.com/index.php` (or .html) you don't need to do anything to make it do that. – Novocaine Nov 05 '14 at 14:46
  • Thanks, but how can I set up so I can redirect to the password protected page properly. I have edited my original message so it should read properly now. – debonator Nov 05 '14 at 14:49
  • you don't need any redirect in your .htaccess...if a user goes to `domain.com` or `www.domain.com` they would be shown content from `domain.com/index.php` if that file exists. You said you previously had an index.html page but you replaced it with index.php - you therefore don't need to make any additions to your .htaccess to make it work with the php page it will look at that file automatically. – Novocaine Nov 05 '14 at 14:54
  • I get 401 authorisation page when I visit just the domain name and the login window when I visit the domain.com/index.php I have removed .htaccess redirect. I am wondering if its a server issue. – debonator Nov 05 '14 at 15:50
  • do you get the popup window asking you for the password? Or does that not even show? – Novocaine Nov 05 '14 at 15:56
0

Ok I modified my original question so much I missed the point. I was limiting access to one page, but to achieve what we wanted (login only), we had to remove the from:

<Files "index.php">
  Require valid-user
</Files>

And bingo it works! Thanks a lot for all your help.

debonator
  • 85
  • 2
  • 13