2016-04-13 25 views

回答

1

您可以使用以下規則:

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] 
+0

感謝。 +10 :)'RewriteCond%{QUERY_STRING}!pg =。+ [NC]'和'RewriteCond%{QUERY_STRING}^$'有什麼區別?什麼更可靠? – Becky

+1

'RewriteCond%{QUERY_STRING}^$'是規則的一個條件,它與空查詢字符串**匹配,如果沒有查詢字符串**,並且'RewriteCond%{QUERY_STRING}!^ pg =。+'是一個不同的條件,我們用它來匹配agaist特定的查詢字符串** if query_string!= pg = foo ** – starkeen

2

你可以在你的.htaccess使用方法:

RewriteEngine on 
RewriteCond %{QUERY_STRING} !pg=.+ [NC] 
RewriteRule ^$ first.html [NC,L] 
+1

謝謝。 +10 :)'RewriteCond%{QUERY_STRING}!pg =。+ [NC]'和'RewriteCond%{QUERY_STRING}^$'有什麼區別?什麼更可靠? – Becky

+2

使用'!pg =。+'測試查詢字符串「pg」是否不存在。使用'^ $'時,您測試沒有查詢字符串。 – Croises

相關問題