【问题标题】:Passing $_GET variable using mod_rewrite / Smarty使用 mod_rewrite / Smarty 传递 $_GET 变量
【发布时间】:2013-08-05 10:01:47
【问题描述】:

我在尝试传递作为 event_id 的 $_GET 变量(事件)时遇到了困难。该网站是用 PHP 和 Smarty 模板引擎构建的,并且 mod_rewrite 工作正常。

工作链接/查询字符串:

/event.php?event=2

重写:

/events/2

htacces:

重写规则 ^/events/?$ /event.php?event=$1 [QSA]

查看页面时 /events/2 它正在寻找模板 2.inc.htmlevent.php 已经指定模板为 event.inc.html,它应该显示来自 DB 的事件详细信息。

【问题讨论】:

    标签: php mod-rewrite get smarty


    【解决方案1】:

    在 htaccess 中,前导前缀(包括前缀的尾部斜杠)在您比较之前被剥离,因此 ^/events 永远不会匹配。尝试在 RewriteRule 中删除第一个 /。

    同样去掉第一个 $,这里的输入(rewritelog 会告诉你)是 /events/2,所以永远不会匹配 events/?$。也许你的意思是 ^events/(\d+) 所以你实际上可以使用 event=$1 的替换。

    【讨论】:

    • 感谢您的快速回复。我已将其更改为 RewriteRule ^events/?$ event.php?event=$1 [QSA] 但它仍在寻找 1.inc.html
    • 同样删除第一个 $,这里的输入(rewritelog 会告诉你)是 /events/2,所以永远不会匹配 events/?$。也许你的意思是 ^events/(\d+) 所以你实际上可以使用 event=$1 的替换。
    • 更新到 RewriteRule ^events/(\d+) event.php?event=$1 [QSA] 对吗?但仍在寻找模板 2.inc.html(对不起,我之前输入错误 1)... 警告:Smarty 错误:无法读取资源:“2.inc.html”...
    • 还有什么建议吗?
    猜你喜欢
    • 2013-01-17
    • 2010-12-02
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    相关资源
    最近更新 更多