1

我需要像这样转换一个查询字符串:

http://localhost/view.php?id=12345

进入这个:

http://localhost/12345

但是,我还计划在 URL 的末尾添加一个字符串,以供搜索引擎受益,如下所示:

http://localhost/12345/NameOfTheSkin

有点像 Wowhead 如何做他们的 URL:

http://www.wowhead.com/item=49623/shadowmourne

请注意如何将字符串 "shadowmourne" 更改为任何内容,它仍将指向项目 id 49623

基本上,我需要忽略末尾的字符串。

任何帮助表示赞赏,欢呼。:)

4

1 回答 1

5
RewriteRule ^/(\d+)/?.*$ /view.php?id=$1 [L]

这将重写http://host/1234/some-texthttp://host/1234变成http://host/view.php?id=1234.

详细解释:

^   -- 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

访问regular-expressions.info获取 regexp 的完整指南。

于 2011-05-16T17:53:09.503 回答