脚本宝典收集整理的这篇文章主要介绍了php – Codeigniter 404使用自定义htaccess mod重写时的有效路由,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
情景1(Works Fine):
/ is the websITe root /.htaccess /api/ <this is the CodeIgniter Root,with index.PHP and default CI .htaccess>
/.htaccess:
RewriteEngine On rewriterule ^api/(.*)$/api/$1 [L]
访问mydomain.COM/api/admin/例如让我进入我的admin-controller / index操作,并加载视图.
$_REQUEST的index.PHP上的var_dump显示
array (size=1) 'admin/' => string '' (length=0)
情景2(不行):
/.htaccess /current/.htaccess /current/api/ <this is the CodeIgniter Root,with index.PHP and default CI .htaccess,this is the same folder/files/htaccess as above scenario>
/.htaccess:
RewriteEngine On RewriteRule ^(.*)$/current/$1 [L]
/current/.htaccess:
RewriteEngine On RewriteRule ^api/(.*)$/api/$1 [L]
访问mydomain.com/api/admin/例如让我进入Codeigniter 404页面/视图.
$_REQUEST的index.PHP上的VAR_dump显示(与场景1相同)
array (size=1) 'admin/' => string '' (length=0)
这里发生了什么?我知道htaccess重写是奇怪的,但就Codeigniter所看到的,路由是一样的(admin /).但他们的行为却有所不同.为什么?我尝试了我可以想到的一切,只要我看到,代码标识符看到正确的路径,直到请求对象去,但CI路由器不知道如何使用它不正确.
任何帮助赞赏,让我知道,如果你能想到任何我可以尝试帮助进一步调试.
注意:使用double htaccess的原因是,我可以根据时间/场景安排不同的CI实例(您可以使用重写条件来提供不同的文件夹而不是“当前”文件夹).目前我没有使用这个,所以在方案2中,root只有一个“current”文件夹.
RewriteEngine on RewriteCond $1 !^(index\.PHP) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.PHP/$1 [L,QSA]
<Directory /var/www/html/ci/> Options Indexes FollowSymLinks Allowoverride All Require all granted </Directory>
还要检查在application / config / config.PHP你有:
$config [‘uri_PRotocol’] =’REQUEST_URI’;
希望有帮助…
以上是脚本宝典为你收集整理的php – Codeigniter 404使用自定义htaccess mod重写时的有效路由全部内容,希望文章能够帮你解决php – Codeigniter 404使用自定义htaccess mod重写时的有效路由所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。