【问题标题】:Codeigniter - XAMP - htaccess issueCodeigniter - XAMP - htaccess 问题
【发布时间】:2020-06-18 22:21:23
【问题描述】:

我在这个网站和其他网站上查看了很多提供的解决方案,但似乎找不到有效的解决方案。

我刚刚从 Xamp 下载了 Codeigniter 并将其放在 htdocs 文件夹中。将其名称更改为“notas”。更改notas/config/config.php这样的属性

$config['base_url'] = 'http://localhost/notas/';
$config['index_page'] = '';

使用多种方法在'notas' 中创建了一个 .htaccess 文件。目前,我是这样的

RewriteEngine On

RewriteBase /notas/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

URL http://localhost/notas/welcome 返回 Object not found - 404,welcome 是文件夹中的默认控制器

如果我这样写,我会收到 500 错误

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 

如果我可以提供任何其他数据来帮助解决它,请索取

谢谢

编辑

如果我把 .htaccess 文件像

Satisfy all

Satisfy any

仍然得到 404。我已经重新检查了控制器文件夹内是否存在 Welcome.php 文件

【问题讨论】:

  • 尝试其他htaccess数据stackoverflow.com/questions/10209010/…
  • 尝试了帖子中的所有 htaccess。唯一从 404 变为 500 的是 Ak memon
  • 尝试配置你的 index_page $config['index_page'] = '' 指向你的索引文件

标签: php .htaccess codeigniter xampp


【解决方案1】:

你可以像这样使用动态baseurl:

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','', dirname($_SERVER['SCRIPT_NAME'])).'/';

在 htaccess 中:

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

别忘了在 config.php 中将 $config['index_page'] = 'index'; 设置为 $config['index_page'] = '';

【讨论】:

    【解决方案2】:

    当然,我是第一个打破它的人。我更改了 /notas/index.php 文件的名称,认为它就像一个示例,并希望看到一些不同的东西。正确重命名并将以下 htaccess 工作后

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 
    

    感谢您的帮助。特别感谢 Amit Sharma 让我意识到这一点

    【讨论】:

      【解决方案3】:

      在htaccess中应该是这样的

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

      基本网址应该是这样的

      $config['base_url'] = 'http://localhost/notas/';
      $config['index_page'] = '';
      

      【讨论】:

      • 使用那个 htaccess 仍然得到 404。如果我没记错的话,配置和我发的一样,
      • 是的,它有效。将 localhost/notas/ 重定向到同一页面
      • 在您提到的第一个 htacces 中应该是 RewriteRule ^(.*)$ index.php/$1 [L,QSA]
      猜你喜欢
      • 2011-10-04
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 2016-11-05
      相关资源
      最近更新 更多