< Browse > Home / Internet / Blog article: ".htaccess" tips and tricks

| RSS

".htaccess" tips and tricks

June 30th, 2009 Posted in Internet

By using .htaccess files, we can control access to our web content by allowing/blocking certain user or ip addresses to access.

You may ask why do we need that, if you can do the same by using options like “order, limit” to restrict ip addresses and user actions in httpd.conf.

Fair enough, but there is some limitations.

Given below example:

1) Let say you are a system administrator in ABC company and your company have a few branches over the world. All these branches located in Malaysia, Singapore, Taiwan and China. And each branches will have their own web directories to store all the documents.

Each branches office have a static ip and domain name

Malaysia    1.2.3.4        www.abc.my

Singapore    2.3.4.5        www.abc.sg

Taiwan        3.4.5.6        www.abc.tw

China        4.5.6.7        www.abc.cn

Scenario 1:

You boss came to you and ask whether you could restrict all the web directories, that only allow all the branches access, public user shouldn’t be able to view or access to it.  Well, it’s easy , you just need to change the httpd.conf

httpd.conf

AllowOverride None Options AuthConfig # Allow use of the authorization directives

Order deny,allow

deny from all

allow 1.2.3.4

allow 2.3.4.5

allow 3.4.5.6

allow 4.5.6.7

Scenario 2:

But, in the same time , he wants to access all these directories from his house, which using dial up connection and doesn’t have a static ip address.

Either you advice him to apply a fix line or ask him to register dynamic dns, definitely your boss will not like it.

So the best solution is to control the web content with valid ‘username’ and ‘passwd’,

Simply create a .htaccess in protect folder and add the following lines

Options  Indexes #to enable directory listing

AuthName     “Password Protected by .htaccess #Message that prompt when asking for username and password

Authtype     Basic

AuthUserFile /usr/local/apache2/passwd #password file location

require user boss #username boss

satisfy any #either u r using malaysia,china,singapore n taiwan ip or u have a valid username and password, then u can view and access this directory

if ‘satisfy all’, mean you must have one of the country ip and have to provide valid username and password in order to access.

Generate username and password file

htpasswd -c /usr/local/apache2/passwd boss

-c is to create new passwd file, if u want to use back the existing password file

htpasswd /usr/local/apache2/passwd boss2

Done. It would be easier and provide more flexibility rather than changing the httpd.conf file and restart the webserver to apply the change.

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • MySpace
  • Twitter
Related Posts
  • No Related Posts
Tags:
Follow Discussion

View Comments to “".htaccess" tips and tricks”

  1. how to write a resume Says:

    test

  2. how to write a resume Says:

    test

  3. jobseekers66 Says:

    well work.
    For more jobs visit http://www.staffingpower.com

  4. jobseekers66 Says:

    well work.
    For more jobs visit http://www.staffingpower.com

  5. chenhow Says:

    Thanks, hope it helps :)

  6. chenhow Says:

    Thanks, hope it helps :)

Leave a Reply

blog comments powered by Disqus

World Vision / WWF

World Vision
One Life - Do Something
I support WWF

Subscribe

Follow Me Twitter Follow Me Friendfeed Subscribe RSS to receive content updates in your favorate reader
Follow Me Facebook Follow Me LinkedIn
RSS Subscribe in a reader
RSS Or, subscribe via email:
     

Recent Post

    • [Centos] Kickstart (Unattended) Linux OS installation
    • Singtel Iphone 4 Launching Date
    • Create Bootable USB Drive For Centos Installation
    • PC Server For Research
    • I’m Back Again

Popular Post