I am having huge duplicate issues with my website. First I redirected non-www to www and worked fine.
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
But my website was still accessible through index.php url To solve that problem I modified as:
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
It worked fine but I am having CMS login trouble and it wouldn't let me log in into my CMS. Then I added this:
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
And it still didnt let me login into my CMS. My exact CMS URL is:
www.example.com/admin/index.php
RewriteCond %{REQUEST_METHOD} !POSTto prevent post data from being cleared by a redirect. (Search engines don't send any post request, so no problem)