Liam McArthur
Liam McArthur

Reputation: 1033

Redirect index.php to root (except query string)

I have an old website where I need to redirect index.php to the root to prevent duplicate content. Normally I'd use the following:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]

The problem is, I have some pages such as index.php?id=6, index.php?id=14 that I don't want redirecting to the root.

How could I amend the above .htaccess rule to exclude index.php files that contain these query strings?

Thanks,

Liam

Upvotes: 0

Views: 221

Answers (1)

Croises
Croises

Reputation: 18671

You can add before RewriteRule:

RewriteCond %{QUERY_STRING} ^$

Upvotes: 1

Related Questions