以下是一些實用的 .htaccess 範例,可以不改動 php.ini 及 httpd.conf 便設定伺服器變數:

關閉 magic_quotes_gpc

# Only if you use PHP
<ifmodule mod_php4.c>
php_flag magic_quotes_gpc off
</ifmodule>

減少 Bandwidth 使用量

# Only if you use PHP
<ifmodule mod_php4.c>
php_value zlib.output_compression 16386
</ifmodule>

變更 scripts 副檔名

AddType application/x-httpd-php .php4

以上語句會將 .php4 當成 PHP 程式編譯。

禁止 .htaccess 開放瀏覽

<files file-name>
order allow,deny
deny from all
</files>

變更預設頁面

DirectoryIndex myhome.htm index.htm index.php

自訂錯誤頁面

ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html

開放/禁止瀏覽目錄

# 禁止
Options All -Indexes
# 開啟
Options +Indexes