【问题标题】:I want to remove index.php from codeigniter url我想从 codeigniter url 中删除 index.php
【发布时间】:2013-11-29 09:42:06
【问题描述】:

我想从 codeigniter url 中删除 index.php 我目前尝试的配置为零结果是

文件夹结构: xampp\htdocs\Codeigniter\application\controllers\olx\olx.php xampp\htdocs\Codeigniter\application\views\olx\frmSignup

我在该位置的 HTACCESS 文件 xampp\htdocs\Codeigniter.HTACCESS 对我来说 .HTACCESS 文件中包含以下内容

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

mod_rewrite 是否启用检查使用 phpinfo();

在对 config.php 文件进行更改之后

$config['base_url'] = 'http://mypc/olx';
$config['index_page'] = '';

当尝试访问此网址时

http://mypc/codeigniter/olx/frmSignup i get 404 error

对 routes.php 所做的更改是

$route['default_controller'] = 'olx';
$route['olx/frmSignup']  = 'olx/frmSignup';

请帮助我想在没有 index.php 的情况下访问我的应用程序。我正在使用 Windows7 处理本地主机

【问题讨论】:

    标签: .htaccess codeigniter


    【解决方案1】:

    在 ubuntu 的 /etc/apache2/sites-available/000-default.conf 的虚拟主机文件中将 AllowOverride None 更改为 AllowOverride All 在我的虚拟主机文件中的 /etc/apache2/sites-available/default.conf 中将 AllowOverride None 更改为 AllowOverride All

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All    <---- replace None with All
        </Directory>
        <Directory /var/www >
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All   <---  replace None with All
                Order allow,deny
                allow from all
        </Directory>
    ....
    

    然后将此代码放入codeigniter根文件夹中的.htaccess文件中

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

    它肯定会起作用。

    【讨论】:

      【解决方案2】:
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /Codeigniter
      
      #Removes access to the system folder by users.
      #Additionally this will allow you to create a System.php controller,
      #previously this would not have been possible.
      #'system' can be replaced if you have renamed your system folder.
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
      
      #When your application folder isn't in the system folder
      #This snippet prevents user access to the application folder
      #Submitted by: Fabdrol
      #Rename 'application' to your applications folder name.
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
      
      #Checks to see if the user is attempting to access a valid file,
      #such as an image or css document, if this isn't true it sends the
      #request to index.php
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
      </IfModule>
      

      所以不是 olx,因为它是控制器而不是文件夹

      在配置中

      $config['base_url'] = '';
      $config['index_page'] = '';
      

      在路线中

      $route['default_controller'] = "olx";
      

      并移动您的 D:\xampp\htdocs\Codeigniter\application\controllers\olx\olx.php 到 D:\xampp\htdocs\Codeigniter\application\controllers\olx.php

      olx 应该是这样的

      class olx extends CI_Controller {
      
      
       public function __construct()
         {
             parent::__construct();
      
       }
      
      
      public function index()
      {
      
          echo "test";
          // or $this->load->view('olx/overview.php', $data);
      
      }
      
      }
      

      然后尝试 localhost/codeigniter/ 或 localhost/codeigniter/olx

      【讨论】:

      • 我尝试了您的 .htaccess 文件并尝试使用相同的 404 结果访问以下 url localhost/olx/frmSignup
      • 你的本地主机是什么,如何访问该目录中的 html 文件?认为 url 是问题,而配置现在不同了,而不是 htaccess。
      • localhost/codeigniter/test.html 进一步,如果它在 CI 文件中开发将分别放置在控制器和视图目录中,而不是 index.php 将涉及到我想访问放置在视图文件夹中的文件这样的 URL localhost/olx/frmSignup
      • 我尝试了您的更新建议,但仍然收到 404,让我再次告诉您我的确切文件夹结构 Codeigniter\application\controller\olx\olx.php Codeigniter\application\views\olx\frmSignup.php 和您的信息 frmSignup 是视图而不是控制器。我已经应用了你提到的所有设置,但没有结果
      • 步骤: 1/ 使用 xampp 了解您的 localhost 指向的位置(使用 index.html) 2/ 将 index.html 复制到名为 olx 的文件夹并检查您是否可以使用 localhost 访问 html /olx 3) 复制 codedigniter 并在控制器中使用 echo 进行测试。文件夹 application 和 index.php 应该在你的 olx 文件夹中(不是 olx/codeigniter/application)
      【解决方案3】:

      您只需要在根应用程序文件夹中创建 .htaccess 文件,或者如果您已经拥有,则对其进行编辑。以下 .htaccess 文件适用于我。

      .htaccess

      # BEGIN ci
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      
      RewriteCond ${REQUEST_URI} ^.+$
      RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>
      

      【讨论】:

        【解决方案4】:

        毕竟是朋友说的,你还得做另一件事(我想你是在localhost上做的):

        首先,仔细检查建议: 然后转到Windows托盘,右键单击WAMP图标,然后单击它,转到Apache菜单,然后转到模块,然后检查rewrite_module是否已选中,如果未选中则单击它(表示禁用)以启用它。现在重试并举报...

        【讨论】:

        • 是的,我已经仔细检查了所有建议,在 localhost 上工作并使用 xampp 而不是 wamp 并检查了 mod_rewirte 的加载模块,请建议我陷入这个愚蠢的问题
        【解决方案5】:

        来自http://ellislab.com/codeigniter%20/user-guide/general/urls.html - 尝试

        RewriteEngine on
        RewriteCond $1 !^(index\.php|images|robots\.txt)
        RewriteRule ^(.*)$ /index.php/$1 [L]
        

        【讨论】:

          猜你喜欢
          • 2016-05-14
          • 2014-10-28
          • 2012-06-15
          • 2012-09-21
          • 2011-10-12
          • 2017-07-16
          • 2014-02-28
          相关资源
          最近更新 更多