htaccess

最後更新: 2017-09-27

介紹

 

 


Enable .htaccess

 

用得 .htaccess 的 Folder 要有以下設定

<Directory "">
    ...
    AllowOverride All
</Directory>

AllowOverride 說明

 


某些目錄有 auto indexing

 

Options +Indexes

P.S. 設定某 Folder 不 show

Options All -Indexes

 


Files & FilesMatch

http://datahunter.org/apache_file_directory#files_filesmatch

 


設定不同的 Error Page

 

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

 


寫 rewrite rule

 

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.your_domain.com [NC]
RewriteRule ^(.*)$ http://your_domain.com/$1 [L,R=301]

 


 

 

 

Redirect 301 http://domain_1.com/home http://domain_2.com/

 


設定 File Cache TTL

 

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

 

 


設定不用的 Default page

 

DirectoryIndex business.html

 


Download only Folder

 

# Turn off all options we don't need.
Options None
Options +FollowSymLinks

# If we know how to do it safely, disable the PHP engine entirely.
<IfModule mod_php5.c>
  php_flag engine off
</IfModule>

 


Private Folder

 

Deny from all

 


在某 Sub-Folder 不用 login

 

.htaccess

# apache 2.2
Satisfy Any

# apache 2.4
Require all granted

 

 

Creative Commons license icon Creative Commons license icon