0

I created a CodeIgniter 3 application and I'm trying to redirect all the URLs with index.php to URLs without it.

My .htaccess is:

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]

I'm facing the problem that both the URLs with and without index.php are redirecting on the same page. For example:

https://www.example.com/ and https://www.example.com/index.php

redirecting to the same page.

Also, when I try to apply the index.php on sub-routes like https://www.example.com/index.php/abc, javascript doesn't load.

I've followed this answer but doesn't work in my case: Redirect index.php in CodeIgniter

Thank you

Sanchit Bajaj
  • 23
  • 1
  • 8
  • Your `.htaccess`/mod_rewrite directives rewrite the request to `index.php/?` (a single slash for path-info and the requested URL contained in the query string). However, your example `/index.php/abc` passes the URL as path-info only, no query string? So, which is it? Both? Or more? eg. `/index.php?abc`, `/index.php/?abc`, `/index.php/abc`? – MrWhite Jun 01 '22 at 16:27

1 Answers1

0

Replace your htaccess with this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Azmal
  • 56
  • 4