为pretty的URL htaccess的重写规则重写、规则、pretty、URL

2023-09-02 20:40:48 作者:爱是自讨苦吃

我需要把查询字符串是这样的:

HTTP://localhost/view.php ID = 12345

进入这样的:

的http://本地主机/ 12345

不过,我还计划有对URL的结尾的字符串为搜索引擎从benifit,像这样:

.htaccess伪静态规则转换为IIS的URL重写规则方法

的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:

http://localhost/12345

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.