【问题标题】:how to rewrite and add a new parameter in .htaccess如何在 .htaccess 中重写和添加新参数
【发布时间】:2012-10-13 19:01:44
【问题描述】:

我想使用 mod_rewrite 将一个 url 重写为另一个。但即使在重写之后我也想保留查询参数和 POST 数据。 我想在重写时向url添加一个新参数...... 例如

这个 -> http://example.com/test/?user=234343

To -> http://example.com/othertest/user=234343&new_param=CUSTOM_VALUE //我只需在 .htaccess 文件中输入这个值

如果有人能给我一个例子,那将非常有帮助。

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    未经测试,但尝试:

    RewriteRule     ^test/?user=([0-9]+)$ /othertest/user/$1&new_param=CUSTOM_VALUE [L]
    

    【讨论】:

    • 实际上它应该处理将在 url 中的任何参数.. 我包括用户只是作为一个例子
    • 好吧,我没有意识到这一点。 “/test”到“/othertest”是作为固定要求给出的,还是只是一个例子?
    • 好吧“/test”到“/othertest”可以修复..所以我必须为我的要求添加许多重写规则。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2013-09-17
    • 2020-07-23
    相关资源
    最近更新 更多