【发布时间】:2011-11-09 21:12:57
【问题描述】:
有没有人知道是否可以将其他变量放入您使用 mod_rewrite 基本上分割成变量的 URL 中。
例如,如果我有 URL:
website.com/post/53/post-title/
我正在使用 mod_rewrite 把它变成:
website.com/post.php?postid=53
是否有优雅的方式将其他变量放入“预先重写”的 URL 并将它们保留在我的 post.php 脚本中?
IE,如果我创建如下链接会怎样:
website.com/post/53/post-title/?anothervar=6
到目前为止,我的 mod_rewrite 代码似乎只是丢弃了附加变量并将 URL 发送到 post.php 脚本,如下所示:
website.com/post.php?postid=53
我知道我可以使用 $_SERVER['REQUEST_URI'] 在我的 php 脚本 (AKA website.com/post/53/post-title/?anothervar=6) 中获取原始 URL,然后它被 mod_rewrite 重写,然后将字符串切碎以将其添加到变量中,但我只是想知道是否有更优雅的解决方案只使用 mod_rewrite。
【问题讨论】:
标签: .htaccess mod-rewrite get