没有查询字符串时自定义索引页面

时间:2016-04-13 12:46:18

标签: .htaccess

如果没有查询字符串,如何将默认索引页面设置为first.html?

www.myexample.com/?pg=456    -- should use index.html
www.myexample.com            -- should use first.html

2 个答案:

答案 0 :(得分:2)

您可以在.htaccess中使用:

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

答案 1 :(得分: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]