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

送分小仙女□ 提交于 2019-12-23 17:21:53

问题


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!


回答1:


The RewriteBase in the codeigniter directory should say /codeigniter/

RewriteBase /codeigniter

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



来源:https://stackoverflow.com/questions/13943040/remove-index-php-from-codeigniter-url-in-subfolder-with-wordpress-in-root

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!