Sajid Saleem
Sajid Saleem

Reputation: 63

I need a htaccess rule, if a url contains question mark after main domain

I need a htaccess rule, if a url contains question mark after main domain

for example:

http://example.com/?

or

http://example.com/?xyz

it should be redirected to home / index page

Upvotes: 4

Views: 332

Answers (1)

Amit Verma
Amit Verma

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

Related Questions