2016-08-03 60 views
0

我的下一個網址: www.dude12345.com/section.php?id=5的.htaccess URL和資源

我想是這樣的www.dude12345.com/section/5

我用下面的代碼

Options -MultiViews 
RewriteEngine On 

# redirect "/section.php?id=xxx" to "/section/xxx" 
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC] 
RewriteRule^/section/%1? [R=301,L] 

# internally rewrite "/section/xxx" to "/section.php?id=xxx" 
RewriteRule ^section/([0-9]+)$ /section.php?id=$1 [L] 

它works..my鏈接看起來我多麼希望(www.dude12345.com/section/5)。 但我有一個問題,我的資源沒有裝好。在控制檯中出現如下所示:「無法加載資源:服務器響應的狀態爲404(未找到)www.dude12345/section/images/myimg.png」並且它不正確,需要類似於www.dude12345 /圖片/ myimg.png。我不知道如何解決這個問題。

回答

0

試試這個,它對我來說工作正常。 只要確保mod_rewrite已啓用。

RewriteEngine On 
RewriteRule ^/?section/([^/d]+)/?$ section.php?id=$1 [L,QSA] 
+0

它不工作,它做同樣的事情.. :( –

+0

可以請你文章的網址,它不工作其實我喜歡測試這樣說:www.example.com/section.php?id = 2到www.example.com/section/2而且它工作正常 –

+0

我解決了,問題是資源的鏈接,我不知道絕對鏈接和相對鏈接之間的區別,謝謝你的幫助! –