如何使用mod_rewrite将示例1更改为示例2.
示例1
http://localhost/a/posts/1/12/abcd
示例2
http://localhost/a/members/1/posts/page.php?pid=12
答案 0 :(得分:1)
RewriteRule posts/(\d+)/(\d+)/.* members/$1/posts/page.php?pid=$2 [L]
答案 1 :(得分:0)
将它放在.htaccess文件中:
RewriteEngine On
RewriteRule ^a/posts/([0-9]+)/([0-9]+)/.*$ a/members/$1/posts/page.php?pid=$2 [L]
^ a / posts /表示您的URI应以/ a / posts /
开头
([0-9] +)是一个数字子串,应至少包含一个数字
。* $包含留在URI结尾的任何内容
a / members / $ 1 / posts / page.php?pid = $ 2创建你的结果
在你的情况下:
Requested URL: http://localhost/a/posts/1/12/abcd
URI: /a/posts/1/12/abcd
$1: 1
$2: 12
Request Result: http://localhost/a/members/1/posts/page.php?pid=12