【问题标题】:CodeIgniter htaccess: `[controller]/[function]/[argument]` not workingCodeIgniter htaccess: `[controller]/[function]/[argument]` 不工作
【发布时间】:2018-03-19 10:43:22
【问题描述】:

您好,我成功删除了我网址中的 index.php,但是 [controller folder]/[function]/[argument] 不再起作用了

这是我的过程

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我也改了

$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';

这是我的配置['base_url']

$base  = "http://".$_SERVER['HTTP_HOST'];
$base .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base;

我已经在 apache 中更改了我的 http.conf 允许全部覆盖

我也已经重新启动了我的 xampp,Cna 有人帮助我为什么 [controller folder]/[function]/[argument] 不起作用?

【问题讨论】:

  • 您可以关注此link 进行相同的质量检查。

标签: php apache .htaccess codeigniter


【解决方案1】:

将您的 .htaccess 脚本更新为:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /codeigniter
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

【讨论】:

  • 它不工作 :( 之前,它说找不到 404 页面,现在它说找不到对象
  • 404 是 .htaccess 错误但对象未找到它可能是控制器或模型中某处的错误
  • 我试过这个 RewriteEngine On RewriteBase /codeigniter RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]跨度>
  • 它可以工作,但是当我想更改系统的文件名时,我不想继续更改 RewriteBase,可以这样做吗?
  • htaccess的这段代码是用来从URL中删除index.php的,所以在这种情况下,我们需要使用RewriteBase /
【解决方案2】:
RewriteEngine On
RewriteBase /codeigniter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteBase /[文件名]。

【讨论】:

    【解决方案3】:

    使用它来避免改变你的 RewriteBase

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

    【讨论】:

      猜你喜欢
      • 2016-03-01
      • 2012-04-29
      • 2011-05-29
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2020-03-02
      相关资源
      最近更新 更多