【问题标题】:CodeIgniter - calling main controller resets url to server rootCodeIgniter - 调用主控制器将 url 重置为服务器根目录
【发布时间】:2016-07-11 08:15:46
【问题描述】:

我对 codeigniter 和默认控制器行为有一点问题。 我的 CI 位于 localhost/web/new_info 开发环境的子目录中,与生产路径相同,例如 192.168.30.108/web/new_info。

总是在调用url时喜欢

localhost/web/new_info/welcome

页面将我带到服务器根目录,例如本地主机/。

但我可以通过以下方式调用“欢迎”控制器:

  • localhost/web/new_info/
  • localhost/web/new_info/index.php/welcome

我也可以调用welcome的方法

  • localhost/web/new_info/welcome/logout

在我的控制器中有另一个名为 settings 的子目录,其中包含另一个welcome.php intself。我可以毫无问题地直接访问这个控制器并且页面停留在那里

  • localhost/web/new_info/settings/welcome

有.htaccess和mod_rewrite根据设置 http://www.farinspace.com/codeigniter-htaccess-file/.

.htaccess

SetEnvIf Host 192.168.30.108$ CI_ENV=production
SetEnvIf Host localhost$ CI_ENV=development
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/new_info/
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

在 config/development/config.php 我有

...
$config['base_url'] = 'http://localhost/web/new_info/';
$config['index_page'] = '';
...

和通用路线

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

Xampp 和运行 apache2 的真实服务器的行为方式相同。即使在完全禁用 mod_rewrite 并调用欢迎控制器后重定向到服务器根目录。

目前我正在使用 CI 3.0.3,并使用最新的 3.0.6 进行了测试,并且具有相同的行为。

我想要的是调用 localhost/web/new_info/welcome 并留在那里.. 谢谢!

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    好的,我自己发现的.. .htaccess 的愚蠢复制粘贴。

    即行

    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
    

    必须是

    RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ /web/new_info/ [L,R=301]
    

    就我而言。 htaccess 文件的作者并没有在他的页面上提及它。

    但仅更改 htaccess 文件并没有帮助。我必须完全重新启动会话,否则不会应用更改。这对我来说有点不寻常,我认为这个文件的变化是即时的。

    不过,现在很好。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 2013-07-20
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      相关资源
      最近更新 更多