【问题标题】:.htaccess mod_rewrite rule to match the clean URL as well as additional custom parameters.htaccess mod_rewrite 规则以匹配干净的 URL 以及其他自定义参数
【发布时间】:2018-10-21 12:29:19
【问题描述】:

这是我为我的 REST API 找到的一个 .htaccess 文件,它以这种方式重写 URL:rest.php/a/b/c/... -> rest.php ?url=a/b/c/...

RewriteEngine On
RewriteRule ^(.*)$ rest.php?url=$1 [L,NC,NE]

我一直在尝试修改此代码以允许附加 GET 参数,因为在当前表单中它只是忽略它们而 PHP 只看到“url”。这怎么可能?

我想要这样的东西:rest.php/a/b/c/...?filter=word -> rest.php?url=a/b/c/ ...&filter=word

【问题讨论】:

    标签: php rest .htaccess mod-rewrite clean-urls


    【解决方案1】:

    你需要标志QSA(查询字符串追加)

    RewriteEngine On
    RewriteRule ^(.*)$ output.php?url=$1 [QSA,NC,NE]
    

    给我网址

    http://localhost/rest.php/a/b/c/?var2=val2
    

    以下GET参数

    array(2) { ["url"]=> string(15) "rest.php/a/b/c/" ["var2"]=> string(4) "val2" } 
    

    欲了解更多信息,请参阅Rewrite Flag QSA

    【讨论】:

    • 按预期工作,谢谢。没想到这么简单
    猜你喜欢
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    相关资源
    最近更新 更多