Rewrite for an empty query string

痞子三分冷 提交于 2019-12-04 22:54:27

I figured it out. This seems to do the trick pretty well:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/$ /index.home.html

Of course, if there's a better way, I'd love to hear it.

i know this ones pretty old, but better alternative is:

RewriteCond %{QUERY_STRING} -n
RewriteRule ^/$ /index.home.html
starkeen

To match against empty QueryString , we use ^$ in our Condition Pattern. The following rule redirects /file.html to /file2.html but it fails to redirect /file.html?querystring because of the condition.

RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?file.html$ /file2.html? [L,R]

An empty question mark at the end of the Rule is important as it discards the old querystring otherwise the redirected url will look like /file2.html?querystring .

Or alternatively: RewriteEngine on

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?file.html$ /file2.html [L,R,QSD]

The QSD flag don't keep the query string if there is one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!