.htaccess
Z MyDevil.net
We use nginx as our web server, but thanks to our special module, we can use htaccess pseudo standard, which allows you to make your own rewrite rules, change the autoindex style, or even change the PHP version.
All settings can be modified by the user, by creating a .htaccess file in public_html/ directory, or in the directory which settings we wan't to change.
Below we present a few examples of more or less useful .htaccess snippets. Some of them have been sent by our users.
Spis treści |
Changing PHP version
By default, our website will be using PHP in 5.3 version. However, we can easily change that back to 5.2 by adding this line to .htaccess file:
AddType application/x-httpd-php52 .php
Deny hotlinking
Hotlinking means anchoring images on other sites, that are downloaded from our website. If we don't want to allow this, we can add this line to .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://.*\.example.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://.*\.example.com/.*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|bmp)$ - [F,NC]
Securing a directory with a password
We can secure a directory (location) on our website by a password (or even the whole page). To do this, we need to create /usr/home/users/domains/example.com/hasla.passwd file (our logins and passwords will be stored there).
|
WarningThe password file needs to be created by adding the first uesr, invoking: |
htpasswd -c /usr/home/user/domains/example.com/passwords.passwd login
The directory which is meant to be password protected should contain a .htaccess file:
AuthType Basic AuthUserFile "/usr/home/user/domains/domena.pl/hasla.passwd" require valid-user AuthName "Secured Area"
As you can see, AuthUserFile points to the file which we created before. We can use different password and login sets for different directories, by simply creating and specyfying additional password files.
|
ExampleZarządzanie listą użytkowników i haseł |
Removing an user:
htpasswd /usr/home/user/domains/domena.pl/hasla.passwd login
Adding an user:
htpasswd -D /usr/home/user/domains/domena.pl/hasla.passwd login
|
See alsoDevil::WWW - adding new websites. |