加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Codeigniter 404使用自定义htaccess mod重写时的有效路由

发布时间:2020-12-13 16:30:31 所属栏目:PHP教程 来源:网络整理
导读:当使用自定义(有点奇怪)的htaccess文件夹映射时,我有与codeignighter的问题.但是,它在技术上应该是有效的,但是它不是.有人能帮我吗? 情景1(Works Fine): 文件夹结构和关键文件 / is the website root/.htaccess/api/ this is the CodeIgniter Root,with in
当使用自定义(有点奇怪)的htaccess文件夹映射时,我有与codeignighter的问题.但是,它在技术上应该是有效的,但是它不是.有人能帮我吗?

情景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”文件夹.

从CodeIgniter的URI中删除index.php可能会很痛苦.上周我遇到了类似的情况:我的根目录在/ var / www / html和里面/ ci我的项目…所以在/ ci我有以下.htaccess:
RewriteEngine on
RewriteCond $1 !^(index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$index.php/$1 [L,QSA]

在apache2配置文件中,我添加了以下内容:

<Directory /var/www/html/ci/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

还要检查在application / config / config.php你有:

$config [‘uri_protocol’] =’REQUEST_URI’;

希望有帮助…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读