.htaccess tips and tricks
.htaccess (hypertext access) is the default name of Apache’s directory-level configuration file. .htaccess is placed in a particular directory, and the directives in the .htaccess file apply to that directory, and all subdirectories thereof.
The most common feature is to restrict access to a folder by force the user to a login prompt, but there are some other helpful things also that I show you in this posting.
Allow access only for the IP 127.0.0.1
allow from 127.0.0.1
deny from all
Forbid access to files with extensions .bak, .sql, .inc.
deny from all
</FilesMatch>
This line make the “.txt” extension to executable PHP scripts.
Redirceting from web folder “bla” to http://phpsecurity.wordpress.com/
Rewriting you can use to make better reading URLs. It’s very handy for SEO and looks much more friendlier than long-cryptic looking URLs for your visitors.
In this example the URL can be http://example.org/de/ or http://example.org/en/ and the Rewrite engine catches the parameters in the brackets and give the value “de” or “en” to the $lang to index.php.
RewriteRule ^(de|en)/$ /test/index.php?lang=$1
Last but not least, set a password prompt to any directory you want
on linux you create a .htpasswd file with:
than you put this lines to your .htaccess:
AuthGroupFile /dev/null
AuthName “name”
AuthType Basic
<Limit GET>
require valid-user
</Limit>
If you have any problems with .htaccess and you have access to your server, look in the error logs of your apache server. You find them in /var/log/apache2/error.log (depending on system).
3 Comments so far
Leave a reply
[...] Check This Out! While looking through the blogosphere we stumbled on an interesting post today. Here’s a quick excerpt: .htaccess (hypertext access) is the default name of Apache’s directory-level configuration file. .htaccess is placed in a particular directory, and the directives in the .htaccess file apply to that directory, and all subdirectories … [...]
very interesting.
i’m adding in RSS Reader
[...] access with a .htaccess in your wp-admin/ folder. Take a look on an older posting http://phpsecurity.wordpress.com/2007/12/22/htaccess-tips-and-tricks/ where you find solutions for limiting by IP addresses and password [...]