'htaccess redirect url not working /?index.html to /

I have a client project on search engine marketing with a website https://www.iehsacademy.com/, The site is 13 years old. before the client was using the URL structure like with HTML like this: https://www.example.com/?index.html (Home Page), https://www.example.com/?cndc.html,

But last year they completely remake the website URL structure and make it to https://www.example.com/ (Home Page), https://www.exsample.com/about. https://www.example.com/contact.

Now, The old URLs and the new URLs are both working. The client wants and also for SEO purposes we want to block the old URL or redirect them to the new URL. I tried many rewrite conditions on htaccess

RewriteRule ^([a-z]+).html https://www.iehsacademy.com/ [QSA,L]

This one also

RewriteCond %{HTTP_HOST} ^www.iehsacademy.com/?cndc.html$
RewriteRule (.*)$ http://www.iehsacademy.com/$1 [R=301,L]

Not Working anything. The client's developer is also confused. Can anyone help with this or where i am doing wrong?

NB: I took permission from the site owner to share the client's URLs and problems.



Solution 1:[1]

You can use the following redirection rule :

RewriteEngine On

#redirect /?index.html to /    
RewriteCond %{HTTP_HOST} ^www.iehsacademy.com$ [NC]
    
RewriteCond %{QUERY_STRING} ^index\.html$
RewriteRule ^$ https://example.com/? [L,R=301]
#redirect /?foobar to /foobar
RewriteCond %{HTTP_HOST} ^www.iehsacademy.com$ [NC]
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^$ https://example.com/%1? [L,R=301]

Make sure to clear your browser caches or use a different browser to test the redirection. And do not forget to replace the destination domain example.com with your domain name.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1