.htaccess Tricks / Directives

Lately I have been increasingly forced to use file .htaccess (File containing definitions Apache), or to filter IPSites (controlled access to a web page) or to set PHP flags.

1. The first thing a person who is interested in working on an online project directly on the server and does not want the site can be accessed by other users besides him is filtering IPs. The file. Htaccess will be written the following lines:

order deny,allow
deny from all
allow from 83.23.2.4

Thereby Directive blocked access to all users (), Less 83.23.2.4. If work on localhost (with Apache installed) and the webserver site-ul/fisierele want to be visible only in LAN (Local Area Network), use:

order deny,allow
deny from all
allow from 192.168.0.0/24

2. Blocking access to certain IP-uri/domenii webserver.

<limit GET POST PUT>
order deny,allow
deny from 66.57.12.48
deny from .isp.com
allow from all
</limit>

- access to the webserver of ip 66.57.12.48 and the domain * .isp.com is forbidden.

3. Disable Directory Browsing.

Options All –Indexes

Specifically, we prohibit access to folders without index (Index of /).

4. Index change default. (Default page)

DirectoryIndex home.html index.html index.php

A set webserver default will have index.html and index.php index / home files. However, if we want a readme.txt to appear as an index file on a web address, "DirectoryIndex readme.txt" will be written to .htaccess.

5. Blocking referrer sites.

RewriteEngine on
RewriteCond %{HTTP_REFERER} site-blocat.com [NC]
RewriteCond %{HTTP_REFERER} site-blocat-2.com [NC]
RewriteRule .* - [F]

If you have a link of your site on other web pages that do not wish to receive visors, you can use the lines above.

6. Block "hot link" to avoid theft traffic (bandwidth).

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?domeniul-meu.com/.*$ [NC]
RewriteRule .(gif|jpg)$ - [F]

Prohibit another site to use images (jpg and gif) that are hosted on the server.

7. Flags of PHP change. Htaccess

To be more safe, some servers are set register_globals OffHowever, there are scripts (Joomla si MamboFor example) that require the installation register_globals On. If you use a file sharehosting and do not have access php.iniYou can use. Htaccess to change php_flags.

php_flag register_globals On

More definitions for settings in .htaccess, HTACCESS Cheat Sheet

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » Linux » Apache » .htaccess Tricks / Directives
Leave a Comment