2013-03-12 201 views
1

在我打開這篇文章之前,我花了三天的時間嘗試弄清楚這一點,但沒有運氣,所以請幫助我。謝謝~~~~從codeigniter中刪除index.php 2.1.3

好吧,這是我迄今所做的:

  1. 安裝CI 2.1.3的全新副本,沒有任何文件有任何名稱變更
  2. 創建一個新的.htaccess文件到CI ROOT目錄與我在Google上找到的所有結構
  3. 將config ['index_page']更改爲空,例如。 config ['index_page'] ='';
  4. 集配置[ 'uri_protocol'] = 'REQUEST_URI' 或 'QUERY_STRING'
  5. 即使重新啓動MAMP(PHP 5.4)每次我製成上述
  6. 啓用變化時間:的LoadModule rewrite_module模塊/ mod_rewrite.so中的httpd .conf文件
  7. 添加「選項指標的FollowSymLinks多視圖」中https.conf(唯一我不知道)
  8. (我不知道我現在應該嘗試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> 

配置。 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

在應用程序根目錄中包含the.htaccess文件以及index.php文件。(檢查htaccess的擴展名是正確的,BZ htaccess.txt並沒有爲我工作。)

,並添加以下規則.htaccess文件,

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

然後找到你的應用程序下面的行/ 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'; 
+0

請閱讀我的文章上面,這些步驟已經完成。 thx – what 2013-03-12 06:38:26

+0

將.htaccess放在不在根目錄下的應用程序文件夾中 – Shaolin 2013-03-12 06:40:46

1
替換以下變量

enter image description here

注:

的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的文件夾中。

3

試試這個的.htaccess(把這個到項目目錄,即根/聊天這裏):

# 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如果你有項目的子目錄,否則刪除它

0

試試:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

變化codeigniterNameFolder :)