0

我最近将一个功能性的 codeigniter 应用程序转移到了一个新的托管服务提供商,并且遇到了我认为与本主题类似的挑战。总而言之,除非我在 URL 中包含 index.php 引用,否则不会设置我的 $_SERVER['PATH_INFO'] 和 $_SERVER['ORIG_PATH_INFO'] 值。我假设这意味着我的 .htaccess 可能是罪魁祸首或问题的组合。这是我所做的:

  1. 我编辑了 codeigniter 的 config.php 文件以删除 index.php 引用

    $config['index_page'] = '';
    
  2. 我创建了以下 .htaccess 文件以从 URL 中删除 index.php

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      RewriteBase /
    
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      #RewriteRule ^(.*)$ index.php?/$1 [L]
      RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>
    
    <IfModule !mod_rewrite.c>
      ErrorDocument 404 /index.php
    </IfModule>
    

    我在 RewriteRule [L] 和 [QSA,L] 值之间切换并获得相同的行为。

  3. 在 config.php 文件中,我设置了以下值

    $config['uri_protocol'] = 'PATH_INFO';
    

使用上述配置,尝试打开 www.mysite.com/test/1234 只需打开 www.mysite.com。但是当我打开 www.mysite.com/index.php / test /1234 时,$_SERVER[PATH_INFO] => /test/1234,却只打开 www.mysite.com。

当我切换回:

    $config['uri_protocol'] = 'AUTO';

我可以访问 www.mysite.com/test/1234(不需要 /index.php/),但没有设置 $_SERVER[PATH_INFO] 值。

任何建议表示赞赏。

4

1 回答 1

0

开发和生产环境中没有参考 PHP 版本,但乍一看我会尝试更改 cgi.fix-pathinfo 设置:

http://php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo

如果 php.ini 编辑可用。

于 2012-12-05T10:10:24.810 回答