Remove index.php from Codeigniter URL in subfolder with Wordpress in root

.htaccess, codeigniter, php, wordpress

Solution

The `RewriteBase` in the codeigniter directory should say `/codeigniter/`

RewriteBase /codeigniter

Otherwise the rewrite to `index.php` ends up going to wordpress' router.

Problem

I'm having some issues with a Codeigniter app in a subfolder on my server along with a Wordpress install in the document root. If I hide the `index.php` of the Codeigniter URL with `.htaccess` /codeigniter/.htaccess ``` DirectoryIndex index.php <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond $1 !^(index\.php|user_guide|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 index.php </IfModule> ``` And get Wordpress to ignore `/codeigniter` with `RewriteCond %{REQUEST_URI} !^/(codeigniter).*$` /.htaccess ``` # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_URI} !^/(codeigniter).*$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> ``` Then navigate to `www.mysite.com/codeigniter/my_controller/my_function`, I get a 404 error `No input file specified.` I found here, that adding a `?` after `RewriteRule ^(.*)$ index.php` solves the Codeiginiter 404 error. /codeigniter/.htaccess ``` RewriteRule ^(.*)$ index.php?/$1 [L,QSA] ``` However I'm now getting a Wordpress 404 error, so it seems if I replace `index.php` with `index.php?` in `/codeigniter/.htaccess`, the Wordpress rewrite rule in `/.htaccess`, `RewriteCond %{REQUEST_URI} !^/(codeigniter).*$` gets ignored. Is there a better way to handle this? Thanks in advance!

Original source