2013-10-06 37 views
3

我一直在嘗試過去幾個小時在我的LAMP機器中編寫乾淨的URL。Apache重寫 - 本地主機中的乾淨URL

Apache的mod_rewrite已啓用,我試圖使用.htaccess文件將URL GET參數傳遞給我的index.php腳本,該腳本當時只是_GET的var_dump。

我目前的.htaccess是下面的(雖然我已經試過它相當多的變化我就沒有成功其他的答案中找到)

RewriteEngine On 

#Make sure it's not an actual file 
RewriteCond %{REQUEST_FILENAME} !-f 

#Make sure its not a directory 
RewriteCond %{REQUEST_FILENAME} !-d 

#Rewrite the request to index.php 
RewriteRule ^(.*)$ index.php?/get=$1 [L] 

當我指出我的瀏覽器到localhost/MY_PROJECT /測試,我得到的是一個404錯誤說:

未找到

所請求的網址/ MY_PROJECT /測試此服務器上找到。

的Apache/2.2.22(Ubuntu的)在本地主機端口80

服務器顯然我失去了一些東西很明顯這裏,任何幫助嗎?

+1

你需要'RewriteBase /'太,右後'RewriteEngine敘述On' – Yang

回答

3

2的事情,尋找:

  1. 確保的.htaccess啓用
  2. 確保上面的代碼是在my_project目錄。

然後加入RewriteBase線以及:

RewriteEngine On 
RewriteBase /my_project/ 

#Make sure it's not an actual file 
RewriteCond %{REQUEST_FILENAME} !-f 
#Make sure its not a directory 
RewriteCond %{REQUEST_FILENAME} !-d 
#Rewrite the request to index.php 
RewriteRule ^(.*)$ index.php?get=$1 [L] 
+0

這做到了,謝謝! – ppp

+0

不客氣,很高興它爲你解決。 – anubhava