用标题和ID重写动态URL [英] Rewrite URL dynamic with title and id
本文介绍了用标题和ID重写动态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用标题和ID动态重写url.我想动态创建网址
I need to rewrite url dynamically with title and id. I want to make URL dynamically
http://dev.example.com/beweb/iphone-8.html
代替
http://dev.example.com/beweb/newsdetails.php?id=8&title=iphone
当我运行上面的URL时,它就变成了我所需要的..但出现错误
When i run the above URL so it is made dyanamically what i need.. but getting error
" Not Found
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The requested URL /beweb/iphone-8.html was not found on this server."
我使用了以下代码:
RewriteEngine On
RewriteCond %{THE_REQUEST} /beweb/newsdetails.php\?id=([^&\s]+)&title=([^&\s]+) [NC]
RewriteRule ^ /beweb/%2-%1\.html? [NC,R,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^%2-([^.]+)\.html$ /beweb/newsdetails.php?id=$1&title=$2 [QSA,L,NC]
请帮助我.
推荐答案
规则几乎正确.您只是错误地配置了最后一条语句,它应该是:
The rules are almost correct. You just misconfigured the last statement, which should be:
RewriteRule ^([^-]+)-([^.]+)\.html$ /beweb/newsdetails.php?id=$2&title=$1 [QSA,L,NC]
这篇关于用标题和ID重写动态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文