當沒有查詢字符串時,如何設置默認索引頁爲first.html?沒有查詢字符串時的自定義索引頁
www.myexample.com/?pg=456 -- should use index.html
www.myexample.com -- should use first.html
當沒有查詢字符串時,如何設置默認索引頁爲first.html?沒有查詢字符串時的自定義索引頁
www.myexample.com/?pg=456 -- should use index.html
www.myexample.com -- should use first.html
您可以使用以下規則:
RewriteEngine on
#when there are query strings#
RewriteCond %{QUERY_STRING} .+
#Rewrite "/" to "index.html"#
RewriteRule ^$ /index.html? [NC,L]
#when there are no query strings#
RewriteCond %{QUERY_STRING} ^$
#Rewrite "/" to "first.html"#
RewriteRule ^$ /first.html [NC,L]
感謝。 +10 :)'RewriteCond%{QUERY_STRING}!pg =。+ [NC]'和'RewriteCond%{QUERY_STRING}^$'有什麼區別?什麼更可靠? – Becky
'RewriteCond%{QUERY_STRING}^$'是規則的一個條件,它與空查詢字符串**匹配,如果沒有查詢字符串**,並且'RewriteCond%{QUERY_STRING}!^ pg =。+'是一個不同的條件,我們用它來匹配agaist特定的查詢字符串** if query_string!= pg = foo ** – starkeen