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

1
  • Your .htaccess/mod_rewrite directives rewrite the request to index.php/?<url> (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? Commented Jun 1, 2022 at 16:27

1 Answer 1

0

Replace your htaccess with this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Sign up to request clarification or add additional context in comments.

1 Comment

Always give explanation to your answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.