Codeigniter 3 删除 index.php 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20169545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter 3 Remove index.php Problems
提问by Chiribuc
I have a little project that i developed for a client in codeigniter 2.1.4 and now, he insists to migrate to codeigniter 3 DEV version. I know that's not a good ideea but... My problem is that i can't remove the index.php from the url.
我有一个小项目,是我在 codeigniter 2.1.4 中为客户开发的,现在,他坚持要迁移到 codeigniter 3 DEV 版本。我知道这不是一个好的想法,但是...我的问题是我无法从 url 中删除 index.php。
This is my .htaccess file :
这是我的 .htaccess 文件:
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
I have removed the index.php from the config.php file
No luck
I reinstalled the LAMP server (i'm on Ubuntu 12.04'), reconfigured
I have other projects on my local server developed on Codeigniter 2.1.4 and Laravel 4 and they work just fine but this one it's killing me.
Thank you!
我已经从 config.php 文件中删除了 index.php
运气不好
我重新安装了 LAMP 服务器(我在 Ubuntu 12.04 上),重新配置
我在 Codeigniter 2.1.4 和 Laravel 4 上开发的本地服务器上还有其他项目,它们工作得很好,但这个让我很伤心。
谢谢!
回答by Eduvm
I made this way:
我是这样做的:
Created the .htaccess in the root folder of the project with the content:
在项目的根文件夹中创建了 .htaccess 的内容:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php? [L]
Then, in the config.php i modified this line.
然后,在 config.php 中我修改了这一行。
From:
从:
$config['url_suffix'] = 'index.php';
To:
到:
$config['url_suffix'] = '';
回答by Eduvm
Kindly add the below codes to .htaccessfile and include it directly to your /codeigniter_project_folder/.htacess
请将以下代码添加到.htaccess文件中,并将其直接包含到您的/codeigniter_project_folder/.htacess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
[PT,L]
回答by Drixson Ose?a
If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.
如果您的 Apache 服务器启用了 mod_rewrite,您可以使用带有一些简单规则的 .htaccess 文件轻松删除此文件。
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/ [L]
Remove the ?after index.php
删除?index.php 之后
回答by Ganesh Mulay
Add following lines in .htaccess file
在 .htaccess 文件中添加以下几行
$config[‘index_page'] = “”;
$config[‘uri_protocol'] = “AUTO“;
And also Edit application/config/config.phpfile. with
并且还编辑application/config/config.php文件。和
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /project_folder/index.php/ [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It will Work.
它会工作。
回答by Shapon Pal
Make a
.htacessfile in your project root folder/Your_codeigniter_project_folder/.htacessand paste this codeRewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
set a base URL in config.php file
$config['base_url'] = 'http://yourhost/CI_project_folder/';- set URL suffix
$config['url_suffix'] = '.php';
.htacess在您的项目根文件夹中创建一个文件/Your_codeigniter_project_folder/.htacess并粘贴此代码重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
重写规则 ^(.*)$ index.php/$1 [L]
在 config.php 文件中设置一个基本 URL
$config['base_url'] = 'http://yourhost/CI_project_folder/';- 设置网址后缀
$config['url_suffix'] = '.php';
* If not work please check this *
* 如果不起作用,请检查此 *
Make sure in your root folder where
.htacessstay there have not any file which name is same like your controller name. Example: you have ausers.phpcontroller also you have a file in/Your_codeigniter_project_folder/users.phpIf have please remove it/Your_codeigniter_project_folder/users.phpMake sure your server is rewrite mode on( remove # from start of this line)
LoadModule rewrite_module modules/mod_rewrite.so
确保在您的根文件夹中
.htacess没有任何名称与您的控制器名称相同的文件。示例:您有一个users.php控制器,您也有一个文件/Your_codeigniter_project_folder/users.php如果有请删除它/Your_codeigniter_project_folder/users.php确保您的服务器处于重写模式(从这一行的开头删除 #)
LoadModule rewrite_module modules/mod_rewrite.so
回答by Andrew Sam
Create an a new htaccess file in your www/project_folder or your htdocs/project_folder
Make sure mod_rewrite is working my using
echo phpinfo()Simply paste the following code and it should work:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /project_folder/index.php/ [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>Change the project folder to that of your own
在您的 www/project_folder 或 htdocs/project_folder 中创建一个新的 htaccess 文件
确保 mod_rewrite 正在使用我的
echo phpinfo()只需粘贴以下代码,它应该可以工作:
##代码##将项目文件夹更改为您自己的文件夹
回答by gareng
create new .htaccess file on root of your CI project and add your code there. Do not change .htaccess file on application folder. That's work for me
在您的 CI 项目的根目录上创建新的 .htaccess 文件并在那里添加您的代码。不要更改应用程序文件夹上的 .htaccess 文件。这对我有用
回答by Vahid Najafi
Just Download CI version 2.2.0
只需下载 CI 版本 2.2.0
Copy .htaccessand htaccess.txtfrom root and paste it in your Codeigniter 3 project.
从 root复制.htaccess并htaccess.txt粘贴到您的 Codeigniter 3 项目中。
Don't forget to change project name from .htaccessfile.
不要忘记从.htaccess文件中更改项目名称。
回答by Chiribuc
I have clone the git repository again and made a clean install of the lamp and now it works.
我再次克隆了 git 存储库并全新安装了灯,现在它可以工作了。

