Jos*_*osh 1 apache .htaccess rewrite clean-urls
我需要像这样转换一个查询字符串:
HTTP://localhost/view.php ID = 12345
进入:
但是,我还计划在URL的末尾添加一个字符串,以便搜索引擎受益,如下所示:
HTTP://本地主机/ 12345/NameOfTheSkin
有点像Wowhead如何做他们的URL:
http://www.wowhead.com/item=49623/shadowmourne
Run Code Online (Sandbox Code Playgroud)
请注意如何将字符串"shadowmourne"更改为任何内容,它仍将指向项ID 49623.
基本上,我需要忽略最后的字符串.
欢迎任何帮助,欢呼.:)
RewriteRule ^/(\d+)/?.*$ /view.php?id=$1 [L]
Run Code Online (Sandbox Code Playgroud)
这将重写http://host/1234/some-text并http://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
Run Code Online (Sandbox Code Playgroud)
访问regular-expressions.info以获取regexp的完整指南.
| 归档时间: |
|
| 查看次数: |
2881 次 |
| 最近记录: |