1

previously due to incorrect .htaccess logic, many of my http://example.com/path/ url is redirected to https://example.com/index.php?/path/

so there are many pages crawled by Google with https://example.com/index.php?/path/

I am using codeigniter, I do not want index.php in my URL, so I have rewrite rules that remove the index.php from the URL, so below is the rewrite rule for that.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

But since there are many pages already crawled by Google with index.php in the URL, I want to redirect those URL to WITHOUT index.php but this will create conflict and create infinite redirect, one remove then one add, on and on.

RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)index\.php https://example.com%1? [R=302,L]

so when I access example.com/path/ this causes "Too many redirect" issues.

I am stuck with my logic here.

what should I do ?

William
  • 5,526
  • 6
  • 20
  • 42
  • Where did you place this, above or below the existing rewriting? (And what exactly are you trying to match with `(.*)` before `index.php` here?) – CBroe Jul 28 '20 at 12:54
  • @CBroe Hi, I have put below the existing, but I tried moved to top, there's no difference. For the (.*), initially I thought there maybe some url example.com/path/index.php?/path2/ But then now I realized it always at the beginning, I guess that (.*) before index.php is unnecessary. – William Jul 28 '20 at 13:57

1 Answers1

1

Okay, I found the answer here with the same issue, to avoid redirect loop, the key is to use

RewriteCond %{ENV:REDIRECT_STATUS} ^$

Remove and Redirect index.php from CodeIgniter

William
  • 5,526
  • 6
  • 20
  • 42