Configuring your web server with .htaccess


A .htaccess file helps you to configure your web server, such as the Apache web server.

In a .htaccess file, you can declare rewrite rules, prevent image hotlinking, handle bad http requests (404 Not Found), and so on.

You can even use htaccess for basic authentication along with a .htpassword file where you can store usernames and passwords.

The configuration in the .htaccess file affects the current directory including its subdirectories. You can override the .htaccess file in the subdirectories by simply declaring another .htaccess file

Here are some examples:

Handle a bad request (404 Not Found)

.htaccess

Use htaccess for basic authentication (Grant access only to user: gunther with password: today)

.htaccess

.htpasswd

Redirect all requests to news/url to news.php?url=url

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">