我在使用Codeigniter2時遇到了一些麻煩。 基本上我想,這樣從我的網址去掉惱人的「的index.php」:在Codeigniter 2中刪除index.php
- http://localhost/ci_intro/index.php/site/home
Becomes
- http://localhost/ci_intro/home
我跟着一對夫婦已經在堆棧溢出的鏈接,並已發現以下兩個職位:
Remove index.php From URL - Codeigniter 2
而且
Removing index.php from codeigniter-2
執行後,但是能夠對S teps依然沒有喜樂。
我的.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 ^(.*)$ /ci_intro/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 ^(.*)$ /ci_intro/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 ^(.*)$ /ci_intro/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>
我保證mod_rewrite的模塊是在Apache中啓用(我使用的XAMPP在Windows上),但由於某種原因,它只是不工作,我」 d期待它。
我在CodeIgniter2中有兩個視圖,一個叫做Home,另一個叫About。這兩個鏈接彼此。鏈接如下:
<a href="home">Home</a><br/>
<a href="about">About</a>
如果我去我的項目的根URL:
http://localhost/ci_intro/
主頁的索引功能顯示。這很好,和預期的一樣。但是,如果我再單擊鏈接重定向到:
http://localhost/ci_intro/home
or
http://localhost/ci_intro/about
其產生的404。但是,如果我再在網址欄中輸入「地盤」,我的控制器的名稱,鏈接帶我穿越到正確加載的觀點:
http://localhost/ci_intro/site/home
or
http://localhost/ci_intro/site/about
有這麼控制器,在這種情況下網站,從網址中移除完全是作爲使用網站/家庭或網站/在我看來,鏈接有關繞過這種方法的任何已知的方式似乎沒有工作?
感謝您的回覆。我明白你從URL中刪除控制器的意思,因爲它可能會導致在開發過程中丟失範圍。但是,如果是這種情況,我該如何去關聯我的觀點?如果我使用網站/家庭或網站/關於這是第一次罰款,我點擊其中一個,但下一次它鏈接到網站/網站/約。 – jezzipin 2013-04-25 14:07:46
檢查application/config.php中的$ config ['base_url']'並設置它。 – stormdrain 2013-04-25 14:10:11
在這種情況下,我猜這是localhost/ci_intro? – jezzipin 2013-04-25 14:11:39