【问题标题】:Not Able to remove "Index.php" from URL in codeigniter无法从 codeigniter 中的 URL 中删除“Index.php”
【发布时间】:2015-05-26 03:51:35
【问题描述】:

我是 codeigniter 的新手,我正在尝试从 Codeigniter 的 URL 中删除 index.php,但无法做到这一点。 我在我的 .htaccess 文件中编写了代码-

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

我的 Apache mod_rewrite 已启用。

但是当我尝试访问任何控制器而不使用 index.php 时仍然出现 404 错误。

请帮忙。

谢谢。

【问题讨论】:

  • 您是否启用了模组重写模块。你已经删除了 config.php 文件中的 index.php
  • 是的。我已经在我的问题中提到了这一点,并且我已经删除了 index.php 表单配置文件。
  • 我做了上面参考文献中建议的所有事情。但仍然面临同样的问题。
  • 有时,这取决于服务器(例如 GoDaddy),您需要在index.php 之后附加问号。 IE。 RewriteRule ^(.*)$ /index.php?/$1 [L]。也google for far in space codeigniter htaccess 并尝试使用提供的代码。

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:
<IfModule mod_rewrite.c>
    RewriteEngine on 
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>

是我正在使用的代码,它适用于我使用过的每个托管平台。

【讨论】:

  • 还有 application/config/config.php - 将 $config['index_page'] = 'index.php'; 更改为 $config['index_page'] = '';
  • @BushraShahid wat 错误您是否正在实施此答案
【解决方案2】:

这应该对你有帮助,

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

【讨论】:

    【解决方案3】:

    检查这个htaccess文件的代码。

    DirectoryIndex index.php    
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)    
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    你可以在这里找到你的答案参考

    My .htaccess file is not working

    此外,您能与我们分享您的基本网址吗?因为这个错误可能是由于设置了错误的baseurl。

    【讨论】:

    • @Bushra 请注意?在 index.php 后签名
    猜你喜欢
    • 2013-08-09
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2012-11-14
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多