简体   繁体   English

从Codeigniter 2.1.3中删除index.php

[英]Removing index.php from codeigniter 2.1.3

Before I open this post, I did spent three days try to figure out this, but no luck at all, so please help me out. 在我打开这篇文章之前,我确实花了三天的时间来弄清楚这个问题,但是一点都没有运气,所以请帮助我。 Thanks~~~~ 谢谢~~~~

Ok, this is what I've done so far: 好的,这是我到目前为止所做的:

  1. Install a fresh copy of CI 2.1.3, no any name change on any folders 安装CI 2.1.3的新副本,任何文件夹上均未更改任何名称
  2. Create a new .htaccess file to CI ROOT directory with all structures that I found on the Google 使用我在Google上找到的所有结构,向CI ROOT目录创建一个新的.htaccess文件
  3. Change config['index_page'] to an empty, eg. 将config ['index_page']更改为空,例如。 config['index_page'] =''; config ['index_page'] ='';
  4. Set config['uri_protocol'] = 'REQUEST_URI' or 'QUERY_STRING' 设置config ['uri_protocol'] ='REQUEST_URI'或'QUERY_STRING'
  5. Even restart the MAMP ( PHP 5.4) every time I made the change above 每次我进行上述更改时,甚至重新启动MAMP(PHP 5.4)
  6. Enabled: LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf 启用:httpd.conf中的LoadModule rewrite_module modules / mod_rewrite.so
  7. Add 'Options Indexes FollowSymLinks MultiViews' in https.conf ( the only thing I am not sure ) 在https.conf中添加“选项索引FollowSymLinks MultiViews”(我唯一不确定的是)
  8. ( I have no idea what should I try now V_V ) (我不知道我现在应该尝试什么V_V)

Then, I got this: 然后,我得到了:

yes working: http://ci.dev/index.php/welcome/index 是的,可以使用: http : //ci.dev/index.php/welcome/index

not working: http://ci.dev/welcome/index 不起作用: http//ci.dev/welcome/index

Here are some details of what I have now: 以下是我现在所拥有的一些细节:

.htaccess file: .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.php

$config['index_page'] = '';
$config['uri_protocol'] = 'QUERY_STRING';
//$config['uri_protocol'] = 'REQUEST_URI'; 

host file 主机文件

127.0.0.1 localhost
127.0.0.1 test.dev
127.0.0.1 ci.dev 

httpd.conf file 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> 

Please HELP ME OUT ~~~~ 请帮助我~~~~

Thanks 谢谢

================================================================= ================================================== ===============

Thanks everyone who try to help me out here. 感谢所有尝试在这里帮助我的人。 I finally got it works, I think somehow I overcomplicated things after overlooking something simple. 我终于使它工作了,我认为在忽略了一些简单的东西之后,我以某种方式使事情变得复杂了。

I just install another copy of CI2 and only change the .htaccess file with: 我只安装了CI2的另一个副本,仅使用以下命令更改了.htaccess文件:

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

Then, it all works~!!!! 然后,一切正常〜!!!!

Try this .htaccess (put this into root of the project directory ie /chat here): 试试这个.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]

Put RewriteBase if you have project in a sub directory otherwise remove it 如果您的子目录中有项目,则放入RewriteBase ,否则将其删除

Have the.htaccess file in the application root directory, along with the index.php file. 在应用程序根目录中具有.htaccess文件,以及index.php文件。 (Check if the htaccess extension is correct , Bz htaccess.txt did not work for me.) (检查htaccess扩展名是否正确,Bz htaccess.txt对我不起作用。)

And Add the following rules to .htaccess file, 并将以下规则添加到.htaccess文件中,

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

Then find the following line in your application/config/config.php file 然后在application / config / config.php文件中找到以下行

$config['index_page'] = 'index.php';

Set the variable empty as below. 如下设置变量为空。

$config['index_page'] = '';

That's it, it worked for me. 就是这样,它对我有用。

If it doesn't work further try to replace following variable with these parameters ('AUTO', 'PATH_INFO', 'QUERY_STRING', 'REQUEST_URI', and 'ORIG_PATH_INFO') one by one 如果仍然无法正常工作,请尝试将这些变量(“ AUTO”,“ PATH_INFO”,“ QUERY_STRING”,“ REQUEST_URI”和“ ORIG_PATH_INFO”)一一替换

$config['uri_protocol'] = 'AUTO';

在此处输入图片说明

Note: 注意:

htdocs is the root folder htdocs是根文件夹

ci_intro is the code igniter's folder ci_intro是代码点火器的文件夹

if we have the same case, then your .htaccess should be like this 如果我们有相同的情况,那么您的.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>

Notice the RewriteBase /ci_intro/ change the ci_info to your codeigniter's folder. 注意RewriteBase / ci_intro /将ci_info更改为您的codeigniter的文件夹。

Try it : 试试吧 :

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* /codeigniterNameFolder/index.php/$0 [PT,L]

change codeigniterNameFolder :) 更改codeigniterNameFolder :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM