Codeigniter 删除 index.php - htaccess localhost

Codeigniter remove index.php - htaccess localhost

我已经尝试了我在此处找到的关于堆栈溢出的所有解决方案,但没有成功。

我是 运行

使用最新版本的 Smarty 3。一切正常,直到我尝试从 URL 中删除 'index.php'。

config.php

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

$config['index_page'] = '';

routes.php

$route['default_controller'] = 'home';

$route['contact'] = 'contact';

.htaccess

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>
<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 /mypage/test1/
  RewriteBase /responsive_template/
  RewriteEngine on
  RewriteCond  !^(index\.php|images|robots\.txt)
  RewriteRule ^(.*)$ /index.php/ [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>

Apache ' LoadModule rewrite_module modules/mod_rewrite.so ' 已启用

<Directory />

    AllowOverride all

    Require all denied

</Directory>

如果我访问 localhost/responsive_template/index.php/contact 一切正常,只有 localhost/responsive_template/contact 以 404 结尾,仅此而已。

整个 codeigniter 应用程序文件夹位于 c:\xampp\htdocs

下的子目录 'responsive_template' 中

感谢大家的帮助,非常感谢。

BR 大卫

我发现 xamppwamp 这个 htaccess 使用完整。

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond  !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L,QSA]

让你将 htaccess 文件放在主应用程序文件夹的外面

设置你的基础 url 类似

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

Note: You can leave base url blank but some times when you submit a form you will find may not submit correctly. because it shows ip_adress in url instead of localhost

目录

application

system

.htaccess

index.php

With codeIgniter 3 versions make sure also you have class and file names first letter upper case.

文件名示例: Welcome.php

<?php

class Welcome extends CI_Controller {

     public function index() {

     }
}

你应该试试这个:

------------------------------------ config.php ----------------------------

    $config['base_url'] = '';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'REQUEST_URI';// if this will not work. comment this line and remove comment from below line
 // $config['uri_protocol'] = 'AUTO'; 

---------------------------------- .htaccess -----------------------------

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/[=10=] [PT,L]

注意:- 确保您的 .htaccess 文件位于根目录中。在 responsive_template 目录中有 index.php 个文件。