为pretty的URL htaccess的重写规则 [英] htaccess rewrite rule for a pretty URL
问题描述
我需要把查询字符串是这样的:
HTTP://localhost/view.php ID = 12345
进入这样的:
不过,我还计划有对URL的结尾的字符串为搜索引擎从benifit,像这样:
的http://本地主机/ 12345 / NameOfTheSkin
有点像Wowhead的是如何做好自己的URL:
http://www.wowhead.com/item=49623/shadowmourne
请注意,你可以如何改变字符串影之哀伤到任何东西,它仍然指向物品ID 49623
。
基本上,我需要被忽略在结束串。
任何帮助是AP preciated,欢呼声。 :)
重写规则^ /(\ d +)/?.*$ /view.php?id=$1 [L]
这将改写的http://主机/ 1234 /一些文本
和的http://主机/ 1234
到的http://host/view.php ID = 1234
?。
详细说明:
^ - 在字符串的开头匹配
( - 开始的比赛组
\ D + - 匹配一个或多个数字
) - 结束比赛组
/? - 匹配0或1的斜线
* - 匹配任何字符0次或更多次
$ - 匹配字符串的结尾
访问定期-EX pressions.info 的正则表达式的完全指南
I need to turn a query string like this:
http://localhost/view.php?id=12345
Into this:
But, I also plan on having a string on the end of the URL for search engines to benifit from, like so:
http://localhost/12345/NameOfTheSkin
Kind of like how Wowhead do their URL's:
http://www.wowhead.com/item=49623/shadowmourne
Notice how you can change the string "shadowmourne" into anything and it'll still point to the item id 49623
.
Basically, I need the string on the end to be ignored.
Any help is appreciated, cheers. :)
RewriteRule ^/(\d+)/?.*$ /view.php?id=$1 [L]
This will rewrite http://host/1234/some-text
and http://host/1234
into http://host/view.php?id=1234
.
Detailed explanation:
^ -- matches at the start of the string
( -- start match group
\d+ -- match one or more digits
) -- end match group
/? -- match 0 or 1 slash
.* -- match any character 0 or more times
$ -- matches at the end of the string
Visit regular-expressions.info for complete guide of regexp.
这篇关于为pretty的URL htaccess的重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!