【问题标题】:Code Igniter 3 / XAMPP - Remove index.php from urlCodeigniter 3 / XAMPP - 从 url 中删除 index.php
【发布时间】:2021-12-15 02:42:56
【问题描述】:

我已经阅读了多个主题,与遇到类似问题的人一起阅读,但似乎没有一个解决方案对我有用。我的网站托管在 http://localhost/mysite/。

我有一个 codeigniter 站点并且正在使用 XAMPP。

任何时候我想访问我在 url 中有 index.php 的页面(http://localhost/mysite/index.php/newpage 或 http://localhost/mysite/index.php/anothernewpage)

这是我的 .htaccess 文件

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

这是我的配置文件

$config['base_url'] = "http://localhost";
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

这是我的路线

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

我还在我的 httpd.conf 文件 (XAMPP) 中取消了以下行的注释

LoadModule rewrite_module modules/mod_rewrite.so

如果我尝试访问站点的某个区域而不包括 index.php (http://localhost/mysite/newpage),我会收到错误 404 在此服务器上找不到请求的 URL。我必须输入完整的 url http://localhost/mysite/index.php/newpage。谁能帮我弄清楚这个设置有什么问题?

【问题讨论】:

  • 请提供您的文件夹结构

标签: php .htaccess codeigniter xampp


【解决方案1】:

您的基本网址应该是$config['base_url'] = "http://localhost/mysite";

【讨论】:

    【解决方案2】:

    在.htaccess的根目录下(如果不存在,创建一个):

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

    在应用程序/config/config.php 中

    $config['base_url'] = ((isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) || $_SERVER['HTTPS']==1)) ? "https" : "http")."://".$_SERVER['HTTP_HOST']."/";
    

    在 localhost(仅 localhost)中,在 $config['base_url'] 中的 '/' 之后添加站点名称;

    【讨论】:

      猜你喜欢
      • 2015-09-28
      • 2016-11-23
      • 2017-04-04
      • 2020-08-12
      • 2012-03-26
      • 2022-01-06
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      相关资源
      最近更新 更多