【问题标题】:remove requirement of index.php in url for loading controller- PHP xamp删除 url 中 index.php 的要求以加载控制器 - PHP xampp
【发布时间】:2023-04-03 08:35:01
【问题描述】:

我对 Code igniter 和通过 MVC 架构处理表单提交完全陌生。因为,我搜索并尝试了堆栈溢出本身给出的所有灵魂和代码,以从 url 中删除 index.php,但所有这些都没有工作。我知道缺少某些东西,但由于我是 CI 新手,所以我无法识别它。

这是我下面的 .htaccess 代码,

<IfModule authz_core_module>
Require all denied
</IfModule>

<IfModule !authz_core_module>
Deny from all
</IfModule>

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

我也设置了 $config['index_page']=' ';和 $config['uri_protocol']='REQUEST_URI';在 config.php 文件中。

注意:我的 CI 版本是 3x

【问题讨论】:

  • 您在本地服务器上工作?哪个操作系统?
  • 是的,我正在使用 win10 操作系统 ..
  • 你的 htaccess 不正确
  • @AnandPandey 有什么解决方案吗?

标签: php codeigniter xampp


【解决方案1】:

确保你的重写基础是正确的,就像我给出的屏幕截图中给出的那样。每个文件夹中有许多 htaccess 文件。我给出了图像中红色的 htaccess 和结构。

 <IfModule mod_rewrite.c>
      RewriteEngine On
      # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
      #  slashes.
      # If your page resides at
      #  http://www.example.com/mypage/test1
      # then use
      # RewriteBase /projectfolder  //its an example

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

    <IfModule !mod_rewrite.c>
      # If we don't have mod_rewrite installed, all 404's
      # can be sent to index.php, and everything works as normal.
      # Submitted by: ElliotHaughin
      ErrorDocument 404 /index.php
    </IfModule>

【讨论】:

  • $config['base_url'] = 'localhost/project' 在应用程序/config/config.php
  • 很高兴帮助 samrat bhai
【解决方案2】:

我使用 xampp 和 windows 10

放置在项目的主目录中,而不是在应用程序文件夹中。

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

结构

application
system
user_guide
.htaccess
index.php

也试试这些

https://github.com/wolfgang1983/htaccess_for_codeigniter

不要为 get 设置 base_url

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

$config['index_page'] = '';

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2017-04-04
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多