Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite for an empty query string

I'm building in some caching to one of my sites, and I can't seem to find if there's a way to add a condition with mod_rewrite to apply only if the query string on a request is empty.

For example, I'd love to know if I can have a request with no query string like

http://www.example.com/

load the page at

http://www.example.com/index.home.html

But any request with a query string, such as

http://www.example.com/?id=32

to load normally and not be affected by the rewrite.

What am I missing?

like image 832
Justin Russell Avatar asked Sep 02 '10 20:09

Justin Russell


2 Answers

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.

like image 147
Justin Russell Avatar answered Sep 22 '22 15:09

Justin Russell


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

RewriteCond %{QUERY_STRING} -n
RewriteRule ^/$ /index.home.html
like image 22
FluffyNights Avatar answered Sep 21 '22 15:09

FluffyNights