CodeIgniter控制器和cPanel子文件夹具有相同的名称
问题描述:
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!
答
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 :)