1

After removing "index.php" from URL using instructions described here,
cPanel sub-folder is requested when I call a codeIgniter controller which has same name as sub-folder.

Controller and sub-folder name is "sites". So, when I request

example.com/sites

Instead of requesting controller example.com/index.php/sites, it requests sub-folder "sites".

It can be fixed by deleting sub-folder or renaming the controller, BUT I want to know if there is any other solution to resolve this issue.

Thank You!

Aaqib Khan
  • 324
  • 2
  • 11

1 Answers1

1

You can do that via htaccess Rules.

Try this rule:-

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
// Below line will controller instead of directory
RewriteRule ^sites/?$ index.php/sites [L]

OR

RewriteCond %{REQUEST_URI} !^/sites
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

Hope it will help you :)

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42
  • If it is useful then accept the answer so future visitor can find it as useful :) – Ravi Hirani Feb 02 '16 at 12:58
  • Is it a good practice to remove `#RewriteCond %{REQUEST_FILENAME} !-d` to make it generic? To ignore sub-directories and send request **index.php** every time. – Aaqib Khan Feb 02 '16 at 12:59
  • It's not ignoring sub directories. check this link for more detail:- http://stackoverflow.com/a/34875835/4198099 – Ravi Hirani Feb 02 '16 at 13:02
  • In that answer you said **"-d (is test string a valid directory)"**. Doesn't that mean, if we remove this than it will ignore sub-directories? Thank you! – Aaqib Khan Feb 02 '16 at 13:11
  • Okay. Now I am getting your question. Yes you are correct. If we remove it then it will ignore sub-directories. – Ravi Hirani Feb 02 '16 at 13:13