2019年1月8日 星期二

【apache】.htaccess Rewrite 設定

# 打開重寫引擎
RewriteEngine On
# 設定基準目錄,從根目錄開始比對
RewriteBase /
# 比對網址,倘若符合 thumbnail,則轉址到 cache 底下,至此結束。
RewriteRule ^(thumbnail)/([0-9]+/.+)$ cache/$1/$2 [L]
# 重新比對網址,倘若結尾是 mp3, mov, ogg, mp4, avi, wmv,不做任何替代,直接 404,至此結束。
RewriteRule (.[^\.]).(mp3|mov|ogg|mp4|avi|wmv)$ - [NC,F,L]
# 設定比對條件,若請求的網址是檔案。
RewriteCond %{REQUEST_FILENAME} -f
# 重新比對網址,倘若是 cache,但是非 sitemap 底下,結尾是 .cache, .xml, .txt, .log,不做任何替代,直接 404,至此結束。
RewriteRule ^(cache)+/+([^sitemap/])(.+[^/]).(cache|xml|txt|log)$ - [NC,F,L]
# 重新比對網址,倘若請求網址是資料夾。
RewriteCond %{REQUEST_FILENAME} -d
# 在結尾加上 /,至此結束。
RewriteRule ^(.+[^/])$ $1/ [L]
# 重新比對網址,倘若請求網址不是檔案。
RewriteCond %{REQUEST_FILENAME} !-f
# 將請求網址轉給 rewrite.php 這支檔案,至此結束,並連同 Query String 一併傳入。
RewriteRule ^(.*)$ rewrite.php [L,QSA]

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

詳細:https://blog.hinablue.me/apache-note-about-some-rewrite-note-2011-05/

沒有留言:

張貼留言