2013-05-26 38 views
0

我閱讀了大量mod_rewrite的爲笨的其中很多東西都在談論創建.htaccess文件,並在文件中像與codeigniter mod_rewrite發生頭痛〜!

我和笨初學者,所以我從YouTube教程學習。 起初,我只安裝了apache 2.2來運行我的php,並使用mod_rewrite codeigniter後,我意識到它更容易安裝wamp,所以我卸載了apache,然後安裝了wamp,其中包含了一切。

之後,我繼續在youtube上關於mod_write的教程。我用wamp激活了模塊。

創建內部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> 

我去到config/config.php文件,改變

$config['index_page'] = ''; 

事情沒有工作。我得到了404error當時我在

RewriteBase /ci_intro/ 

嘗試一些東西,甚至還刪除了整個項目,因爲我支持的東西之前,我嘗試mod_write。即使在我檢索了備份之後。我仍然沒有得到error404頁面。

我只是不斷獲取..

ci error

由於我使用WAMP,當我去我的本地有一個部分說我的項目,該項目ci_intro ......我一下就可以了上面的圖片出來了。 我把我的鼠標來檢查什麼的鏈接顯示當鼠標懸停和鏈接顯示

[CODE] http://localhost/ci_intro[CODE]

任何人都知道這是怎麼回事呢?

回答

0

您得到的瀏覽器頁面是使用虛假或未註冊的域名的結果...瀏覽器無法將其解析爲IP地址,因此它通過將您的請求重新解釋爲「幫助」您搜索詞。

發生這種情況是因爲您使用「www.domain.tld」而不是「localhost」訪問您的網站。

我不知道你正在使用的WAMP分佈狀態(有許多 「WAMPs」),但你的選擇是:

A)編輯Windows HOSTS文件(C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ etc \ hosts)本地解析「www.domain.tld」爲本地IP地址127.0.0.1(並確保您的VirtualHost或Server具有該域名作爲其ServerName指令的一部分)。

B)使用「localhost」,而不是... http://localhost/

C)使用WAMP是自動設置網站VirtualHosts爲您和具有LocalDNS擁有像WAMP,開發專業做 - 所以沒有上述事項。

現在一旦你通過了,可能會有一些其他問題......我猜測.htaccess文件應該在DocumentRoot文件夾本身。

+0

當我進入C:\ WINDOWS \ SYSTEM32 \ DRIVERS \等\主機 這是我看到 127.0.0.1本地主機 127.0.0.1 \t mpa.one.microsoft.com 127.0.0.1本地主機 127.0。 0.1本地主機 雖然 – Dora

+0

@ user1850712,所有其他註釋掉,添加行:「127.0.0.1 www.domain.tld」,保存文件,然後關閉您的瀏覽器(所有標籤和窗口)。這將導致您的瀏覽器將您的虛假域名解析爲本地系統IP(始終爲127.0.0.1)。 – rightstuff

+0

剛剛嘗試過,但它只會將我帶回本地主頁,並在URL中顯示www.domain.tld而不是localhost。 – Dora