Rameshwor Dahal
Rameshwor Dahal

Reputation: 1

.htaccess redirect for index.php file

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

Upvotes: 0

Views: 413

Answers (1)

Olivier Pons
Olivier Pons

Reputation: 15816

Darthenius is right, but forgot to mention one thing: use uppercase properly (even though it's not needed, it's always a good habit to take):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]

RewriteCond %{REQUEST_URI} !(/admin/index\.php)
RewriteCond %{REQUEST_URI} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]

Please tell me if it works

Upvotes: 1

Related Questions