【问题标题】:Can you somehow use the base-tag to pass parameters?你能以某种方式使用 base-tag 来传递参数吗?
【发布时间】:2016-01-18 14:54:20
【问题描述】:

我为一个大型框架编写了一些自定义调试代码,通过将?debug 添加到任何 url 我得到了一些自定义服务器数据。每当我单击一个链接时,?debug 就会消失,我可以以某种方式将其保留在那里吗?我的想法是使用基本标签:

If(isset($_POST['debug']{
    <base href="/images/">
}

但它似乎不支持参数。有没有类似的东西?

【问题讨论】:

    标签: html query-string getparameter


    【解决方案1】:

    假设您使用的是 Apache,您可以只使用 mod_rewrite:

    RewriteEngine on
    
    # Test whether the current query string contains 'debug'
    RewriteCond %{QUERY_STRING} !debug
    
    # Internally append ('query string append') the extra parameter
    RewriteRule (.*) $1?debug [QSA]
    

    要将此行为限制为仅限您的计算机,请在两者之间添加一个额外条件:

    # Only trigger the rule if the remote IP address exactly matches the string
    RewriteCond %{REMOTE_ADDR} =192.168.1.1
    

    并用你自己的IP替换。

    【讨论】:

      【解决方案2】:

      我认为您有 2 个选项 - “最简单的”是在服务器端添加一个会话变量,显示所有返回的页面都应该处于调试模式。这带来了它自己的副作用,依赖会话就是其中之一。

      更好的选择是将调试查询字符串添加到页面上的所有链接。这可以在呈现页面时在服务器端完成,但最好的方法可能是使用 jQuery 之类的东西自动将其添加到所有链接中(如此处所述:Jquery : Append querystring to all links

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-02-14
        • 2020-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-27
        • 1970-01-01
        相关资源
        最近更新 更多