Reputation: 63
I need a htaccess rule, if a url contains question mark after main domain
for example:
or
it should be redirected to home / index page
Upvotes: 4
Views: 332
Reputation: 41219
Try this in root/.htaccess
RewriteEngine on
RewriteCond %{QUERY_STRING} ^.*$
RewriteRule ^/?$ /? [NC,L,R]
Empty question mark at the end of target path is importent as it discard the orignal querystrings, in apache 2.4 and later you can use QSD Flag to discard query strings.
If the rule above fails, then try
RewriteEngine on
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC]
RewriteRule ^/?$ /? [NC,L,R]
Upvotes: 1