2016-08-03 56 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

我解决了,问题是资源的链接,我不知道绝对链接和相对链接之间的区别,谢谢你的帮助! –