【问题标题】:remove index.php by using htaccess doesnt work使用 htaccess 删除 index.php 不起作用
【发布时间】:2017-02-01 05:50:33
【问题描述】:

我想通过使用根目录中的.htaccess 文件来删除index.php

我的框架是 codeigniter。

我的 htaccess :

AddType application/x-httpd-php53 php53 php

php_flag  log_errors on
php_flag  display_errors on
#php_value error_reporting 8
php_value error_reporting E_ALL

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{HTTP_HOST} ^megarooz.com/$ [NC]
RewriteRule ^(.*)$ http://megarooz.com/$1 [R=301,L]

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

order allow,deny
allow from all

我的配置:

$config['base_url'] = 'http://megarooz.com';


$config['index_page'] = '';

我收到了这条消息:

Not Found
The requested document was not found on this server. 

它不起作用:

http://megarooz.com/admin/Admin/login

效果很好:

http://megarooz.com/index.php/admin/Admin/login

【问题讨论】:

  • 是否在 Apache 中安装并启用了 mod_rewrite?另外,尝试将on 更改为On
  • @Magnus Eriksson 如何查看mod_rewrite 是否启用?
  • 您使用的是什么操作系统?顺便说一句,你在 PHP 5.3 上吗?你应该真的升级你的系统。 5.3 很久没支持了。甚至 5.6 也已结束主动支持。
  • 我的php版本是5.5.38

标签: php apache .htaccess codeigniter


【解决方案1】:

尝试使用下面的代码

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

【讨论】:

    【解决方案2】:

    试试这样......

    1.在您的根文件夹中。 .htaccess文件

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

    2.在application/config/config.php设置以下内容

    $config['base_url'] = 'http://megarooz.com/';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'REQUEST_URI';
    

    希望它有效。

    【讨论】:

      【解决方案3】:

      由于这是 Stack 上一个非常常见的问题,我希望您下次进行更多研究,因为它充满了 CI 的 index.php 问题。尽管我确实同意 CI 的 htaccess 有点糟糕,因为它也并不总是对我有用,但我最终做的是从 Laravel 获取 htaccess。

      Options +FollowSymLinks
      RewriteEngine On
      
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
      

      从来没有遇到过问题,希望这会奏效。

      【讨论】:

        猜你喜欢
        • 2011-08-03
        • 2015-01-20
        • 2014-08-12
        • 2013-12-29
        • 2019-01-14
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多