Contact Systems Misc |
Table of Contents.htaccess ConfigurationThe .htaccess file allows you to configure how the web server handles pages in your public_html directory. You can use this to restrict access, modify the look of indexes, rewrite URLs, or add the automatic processing of additional file types. Restricting AccessYou can use the Restrict Access Based on IP AddressYou can restrict access by IP address. This would allow you to restrict access to users within the University or just the CS Department. You can also password protect pages so that users will be prompted to enter a username and password to access your pages. If you want to restrict access to files in ~/public_html/restricted/ to users in the CS Department, create a .htaccess file that looks like this: jdash@ix: ~/public_html/restricted 603$ cat .htaccess <Limit GET POST PUT> require host cs.uoregon.edu </Limit> Make sure the file has permissions Restrict Access by PasswordIf you want to password protect your pages you'll need an htpasswd file as well as a .htaccess file. Create your htpasswd file with the htpasswd command. In this example the jdash@ix: ~/etc 549$ htpasswd -c htpasswd snoopy Adding password for snoopy. New password: Re-type new password: jdash@ix: ~/etc 550$ The AuthUserFile /home/users/jdash/etc/htpasswd AuthGroupFile /dev/null AuthName "project name" AuthType Basic require valid-user Adjusting Automatic IndexesIf you are using the built-in auto-indexing features of Apache, you can control this using an Suppose you had a directory of documents. You'd like to announce which documents are your favorites, by adding a star icon. You also want all of the files sorted with the newest first. This can be done by creating an .htaccess file containing the following commands (change myfav to your favorite documents): IndexOrderDefault Descending Date AddIcon /icons/misc/star.gif myfav Controlling File Typesand .PHP as a CGI.Another interesting application of the NB: You don't need to do this on our server ix.cs.uoregon.edu to make PHP execute as a CGI, because we do this for you in our server configuration. The most common use for this is probably to execute .php files using the CGI interface rather than the built-in mod_php interface. This would only be used if you were installing a bulletin board or content management system that had more .php files than were easy to convert to .cgi, and would allow you to control access to the data files. To do this you would create a RemoveHandler .php AddType application/my-httpd-php .php Action application/my-httpd-php /~jdash/php.cgi You would also need to create #!/local/bin/php <?php $pwuid = posix_getpwuid(posix_geteuid()); if (is_file($_SERVER['PATH_TRANSLATED']) && ($pwuid['name'] === 'nobody' || $pwuid['name'] === 'apache' || fileowner($_SERVER['PATH_TRANSLATED']) == posix_geteuid())) { chdir(dirname($_SERVER['PATH_TRANSLATED'])); include(basename($_SERVER['PATH_TRANSLATED'])); } ?> Make sure the permissions on both files are Other possible uses for this technology are: convert/resize images before downloading, automatically create html from text pages, or add a counter database for downloading various other data types. External Links |