這是我的.htaccess這感覺就像它的方式,以及它可以變得更高效。我目前遇到的問題是,由於這些規則是在重寫配置文件視圖和vcard視圖的順序目前不起作用。我發現取決於按照什麼順序放置這些RewriteRules會影響其他人的行爲。如果你問我,它有點噩夢。我可以使我的htaccess更清潔,更多optomized?
我的網站結構並不複雜。我有3個PHP頁面,每個頁面使用$ _GET值處理項目的不同操作,以檢查人員是否在正確的位置並使用正確的參數。我遇到的一件事是建立友好的鏈接,以便人們可以使用熟悉的url路徑轉到圖片或其他東西。
那好吧,哦,哦。另外,當我想使用選項或設置時,我有一個動態的RewriteRule模板,然後我可以使用最後2個佔位符來放入我的數據。
# Options:
# -MultiViews: Turns off multiviews so it doesn't interfer with our rewrite rules
# -Indexes: Stop directory listings
# +FollowSymlinks: Let out rewrite rules work
Options -MultiViews -Indexes +FollowSymlinks
RewriteEngine On
RewriteBase/
# Error page
# Force add trainling slash
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ http://foo.bar/$1/ [R=301,L]
# Prepent www if not exist in URI
RewriteCond %{HTTP_HOST} ^foo\.bar$
RewriteRule (.*) http://www.foo.bar/$1 [R=301,L]
# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC,OR]
RewriteCond %{REQUEST_FILENAME} -l [NC]
RewriteRule .* - [L]
# Rewrite for page view
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3 [QSA,L]
# Condition to ignore regular links
RewriteRule ^library/templates/([^/]+)/([^/]+)/([^/]+)/?$ library/templates/$1/$2/$3 [QSA,L]
# Rewrite for dynamic page settings
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2&page=$3&$4=$5 [QSA,L]
# Rewrite for account view
RewriteRule ^([^/]+)/([^/]+)/?$ account.php?type=$1&user=$2 [QSA,L]
# Rewrite for site default resources location
RewriteRule ^([^/]+)/([^/]+)/theme/s/([^/]+)/([^/]+)/([^/]+)/?$ library/themes/site/$3/$4/$5 [QSA,L]
# Rewrite for profile view
RewriteRule ^([^/]+)/?$ profile.php?user=$1 [NC,L]
# Rewrite for vCard view
RewriteRule ^([^/]+)/vcard/?$ vcard.php?user=$1 [NC,L]
# Rewrite for user themes location
#RewriteRule ^([^/]+)/([^/]+)/theme/([^/]+)?$ library/themes/users/$3 [NC,L]
#error codes
#RewriteRule ^error/([^/]+)/?$ error.php?code=$1 [NC,L]
thx,我是通過自己學習完成的,因此我沒有真正瞭解專業草擬的htaccess的樣子。你實際上用你提出的兩點來對待我。我會研究它,看看我可以解決我的訂單問題。謝謝 – Eli 2011-03-25 01:40:31