从 codeigniter 2.1.3 中删除 index.php
Posted
技术标签:
【中文标题】从 codeigniter 2.1.3 中删除 index.php【英文标题】:Removing index.php from codeigniter 2.1.3 【发布时间】:2013-02-27 14:05:34 【问题描述】:在我打开这篇文章之前,我确实花了三天时间试图弄清楚这一点,但一点运气都没有,所以请帮助我。谢谢~~~~
好的,这就是我目前所做的:
-
安装 CI 2.1.3 的新副本,对任何文件夹都没有任何名称更改
使用我在 Google 上找到的所有结构创建一个新的 .htaccess 文件到 CI ROOT 目录
将 config['index_page'] 更改为空,例如。 config['index_page'] ='';
设置 config[‘uri_protocol’] = ‘REQUEST_URI’ 或 ‘QUERY_STRING’
甚至每次我进行上述更改时都重新启动 MAMP (php 5.4)
已启用:httpd.conf 中的 LoadModule rewrite_module modules/mod_rewrite.so
在 https.conf 中添加“Options Indexes FollowSymLinks MultiViews”(唯一不确定的)
(我不知道我现在应该尝试什么 V_V)
然后,我得到了这个:
是的,工作:http://ci.dev/index.php/welcome/index
不工作:http://ci.dev/welcome/index
以下是我现在拥有的一些详细信息:
.htaccess 文件:
# I got 500 error if I uncommend this line: <IfModule mod_rewrite.c>
#http://ci.dev/index.php/welcome/index this is works fine only if the above line commend out
RewriteEngine On
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ /index.php/?$1 [L]
# I got 500 error if I uncommend this line: </IfModule>
config.php
$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
//$config['uri_protocol'] = 'REQUEST_URI';
主机文件
127.0.0.1 localhost
127.0.0.1 test.dev
127.0.0.1 ci.dev
httpd.conf 文件
#the following line also enabled
LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf
...
# The following code I placed at the bottom of https.conf file
NameVirtualHost *
<VirtualHost *>
ServerName localhost
DocumentRoot "/Applications/MAMP/htdocs"
</VirtualHost>
<VirtualHost *>
ServerName ci.dev
DocumentRoot /Users/coda/Sites/ci
<Directory /Users/coda/Sites/ci>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName test.dev
DocumentRoot /Users/coda/Sites/test
</VirtualHost>
请帮帮我~~~~
谢谢
================================================ ===================
感谢所有在这里尝试帮助我的人。我终于让它工作了,我认为在忽略了一些简单的事情之后,我不知何故把事情复杂化了。
我只是安装了 CI2 的另一个副本,并且只更改了 .htaccess 文件:
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
然后,一切正常~!!!! ——
【问题讨论】:
【参考方案1】:试试看:
RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule .* /codeigniterNameFolder/index.php/$0 [PT,L]
更改 codeigniterNameFolder :)
【讨论】:
【参考方案2】:试试这个 .htaccess(把它放到项目目录的根目录下,即这里的 /chat):
# To remove index.php from URL
RewriteEngine On
# RewriteBase /chat
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
如果您在子目录中有项目,请将 RewriteBase
放入,否则将其删除
【讨论】:
【参考方案3】:注意:
htdocs 是根文件夹
ci_intro是代码点火器的文件夹
如果我们有同样的情况,那么你的 .htaccess 应该是这样的
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [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>
注意 RewriteBase /ci_intro/ 将 ci_info 更改为您的 codeigniter 文件夹。
【讨论】:
【参考方案4】:在应用程序根目录中拥有 .htaccess 文件以及 index.php 文件。 (检查 htaccess 扩展是否正确,Bz htaccess.txt 对我不起作用。)
并将以下规则添加到 .htaccess 文件中,
RewriteEngine On
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php/$1 [L]
然后在你的 application/config/config.php 文件中找到下面一行
$config['index_page'] = 'index.php';
将变量设置为空,如下所示。
$config['index_page'] = '';
就是这样,它对我有用。
如果它不起作用,请尝试用这些参数('AUTO'、'PATH_INFO'、'QUERY_STRING'、'REQUEST_URI'和'ORIG_PATH_INFO')一一替换以下变量
$config['uri_protocol'] = 'AUTO';
【讨论】:
将 .htaccess 放在应用程序文件夹中,而不是在根目录中以上是关于从 codeigniter 2.1.3 中删除 index.php的主要内容,如果未能解决你的问题,请参考以下文章
无法从 codeigniter 中的 URL 中删除“Index.php”