tags: apache   archive   business   charity   climbing   cluster   comic   database   email   exchange   family   fm2008   hack   humour   linux   liverpool   microsoft   money   mysql   network   oes   opensource   outlook   php   pictures   poem   process   project   real_life   review   rss   science   security   software   sql   thought   tsm   updates   webdev   website   windows  

.htaccess password protect

Wed, 09 Jan 2008 07:42:15

A 30 second recap on how to protect your site with a username and password using .htaccess

  • Find and run 'htpasswd -c /var/www/html/sec/pass.htpasswd ryan'
  • -c is to create a new file, ryan is the username. You'll be prompted for a password

  • Create a .htaccess in the directory you want to protect and add the following lines:
  • AuthName "Secure Login"
    AuthType Basic
    AuthUserFile "/var/www/html/sec/pass.htpasswd"
    require valid-user

    Here we're saying the user just needs to exist in the file we created earlier, for more detailed setups, use google.

  • Ensure that 'AllowOveride All' is set for the directory in which .htaccess lives, otherwise the config file wont be processed.
  • Cheers
    Ryan Partington

Force Type with .htaccess

Mon, 24 Sep 2007 05:17:42

The .htaccess can be used for many apache http server functions. Today we're going to take a quick look at 'force type'. Force Type allows you present a webpage in another format than default. For example, if we have index.html but would like apache to process it as php, we could add

<Files article>
ForceType application/x-httpd-php
</Files>

to the .htaccess file. This allows you to create a site which looks static (.htm or .html) but process the data and content as php.

Once place I use this is with the article page, if you click in to this article it would look something like this http://ryanpartington.com/article/freewebdesign/ - article is actually a php page, and I pass the variable freewebdesign/ to a MySQL query.

Thanks
Ryan Partington