【问题标题】:can't remove index.php with .htaccess无法使用 .htaccess 删除 index.php
【发布时间】:2012-09-21 16:34:25
【问题描述】:

我已经安装了 codeigniter,我想在访问 localhost/aplication/index.php 时从 url 中删除 index.php。我已经从 httpd.conf 设置取消注释 mod_rewrite.so 这是我的 .htaccess 文件:

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

当我从 localhost/aplication/index.php/data/users/12 访问 url 但不使用此 url localhost/aplication/data/users/12 时,它会成功。

我该如何解决这个问题??

【问题讨论】:

标签: .htaccess codeigniter


【解决方案1】:

尝试关注这个关于codeignitor pretty urls的页面。你的规则看起来是正确的,但我对正则表达式很糟糕。

需要研究的一些事情是使用 phpinfo(); 检查 mod_rewrite 是否可用。该链接中的第三步还讨论了使用 a2enmod 启用 mod_rewrite。并确保重新启动 Apache。

【讨论】:

    【解决方案2】:

    检查你的配置文件应该有一行说:

    $config['index_page'] = 'index.php';
    

    您可以将此变量设置为 '' 或者您可以完全注释掉这一行,无论哪种方式,它都是从您的 codeigniter url 中删除 index.php 过程的一部分。

    【讨论】:

      【解决方案3】:

      这是删除 index.php 的方法:

      根文件夹中的htaccess文件:

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

      用于管理一些静态页面,例如:example.com/about、example.com/contact、example.com/terms 等

      配置路由文件并编辑:

      //the controller that will be when it is exampl.com
      $route['default_controller'] = 'YOUR_MAIN_CONTROLLER_NAME_HERE';
      //I creted this for pages that are created dynamically or for displaying error when I want
      $route['404_override'] = 'friendlyPages';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-06
        • 1970-01-01
        • 2014-02-19
        • 2021-10-02
        • 2015-01-20
        • 2023-03-07
        相关资源
        最近更新 更多