Back to General Articles

Protecting forum parts by htaccess
by HolyKiller 06 Jan 2010
Rating: (2 votes - 5.00 average)

I just found a thread about protecting Admin Panel via htaccess. It is usable and +1 for the author, but... The thing is, it supports only one login which need to be shared, if you have more admins, or, you want to protect Moderator panel too and have more than one moderator. So after every staff change, you need to change your pass and tell everybody, there is a new password. Second thing, you need to edit existing vbulletin files, so, you probably need to edit them over and over again after every vBulletin update. AND the third thing, that password are plain-text stored, which is not good at all.

Once again, i dont want insult that thread author, but, i just want share my way, how to do it more "sophisticated" AND secure

1) Create a files named .htaccess and .htpasswd
(if you using Windows and get error message, create a htaccess.txt and htpasswd.txt files for now)

2) In htaccess add:
Code:
AuthUserFile /*link.to.your.protected.dir*/.htpasswd
AuthType Basic
AuthName "Protected Area"
require valid-user
- You need to set a correct path, so, you can get it easilly like this:
2a) Create a new file and add code:
Code:
<?
 phpinfo();
?>
2b) Name that file like info.php and put it INTO your directory which you want to procect (admincp, cpmod, ... etc...)

2c) Open your browser and type path to your info.php file, so something like:
http://www.yoursite.com/forum/admincp/info.php

2d) You get a full information about your php. You need to find (use browser function) a row named SCRIPT_FILENAME and on the right side you can see absolute path to info.php file. Something like this: /var/www/yoursite.com/forum/admincp/info.php

2e) Copy that path into htaccess file and rewrite info.php to .htpasswd. So you actually got this in .htaccess file:

Code:
AuthUserFile /var/www/yoursite.com/forum/admincp/.htpasswd
AuthType Basic
AuthName "Protected Area"
require valid-user
3) Now you need to set up some usernames nad hashed passwords. I recomanded http://www.kxs.net/support/htaccess_pw.html page. It rly helps you. Just insert your username and password (that name and pass, what you want to use for protecting your files) and click on "Create Password". So for example we use username Anton and passsword whiteglass and we get this:

Code:
Anton:H8hXcFoiSNgtY
and thats exactly what we need, so we just copy&paste this into .htpasswd file. By the way, you can add more users into .htaccess file. Just generate more name/pass and add them, one on each row. So you can use your own name and pass, and your co-admin another username and password. Or if you protecting your modcp directory, you can create specific login for each moderator

4) Save both files and upload them on your server.

5) Now, try to access your admincp. You shoud get a small window popped up. If not, you did something wrong and you need to start over.

BTW: If you used htaccess.txt and htpasswd.txt names, you need to rename them after upload. The correct names are .htaccess and .htpasswd WITH that DOT on start!

Dont forget to delete that info.php file

Hope it helps

Yea, and sorry for my english, i'm from Czech republic

Holy

vblts.ru supports vBulletin®, 2022-2024