【问题标题】:Query Sting in my own MVC Framework在我自己的 MVC 框架中查询字符串
【发布时间】:2013-07-13 11:39:42
【问题描述】:

我有自己的小 MVC 框架。 它有自己的 .htaccess 文件,可将 URL 重定向到

index.php?Load=$1

所以每次我尝试运行查询字符串例如:

http:\\localhost\contact\func?id=56032&post=2

只需http:\\localhost\contact\func

如何通过 $_GET 变量获取查询字符串 (id,Post) ?

【问题讨论】:

    标签: php .htaccess mod-rewrite query-string


    【解决方案1】:

    查看 htaccess 文件中的 QSA 标志:http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa

    使用此标志,将保留重写 url 上的参数。因此,使用此代码:

    RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
    

    对 /pages/123?one=two 的请求将被映射到 /page.php?page=123&one=two。

    【讨论】:

      【解决方案2】:

      您可以使用parse_url()parse_str()

      parse_str(parse_url($_GET["Load"], PHP_URL_QUERY), $_GET);
      

      然后你可以通过$_GET["post"];访问

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-08
        • 1970-01-01
        • 2021-04-13
        • 1970-01-01
        • 2012-03-18
        • 1970-01-01
        • 1970-01-01
        • 2013-01-22
        相关资源
        最近更新 更多