【问题标题】:Htaccess parameter overwrite + allow additional params?Htaccess 参数覆盖 + 允许附加参数?
【发布时间】:2013-03-12 18:09:57
【问题描述】:

我的 .htaccess 文件中有一条规则可以用干净的路径覆盖丑陋的参数 url。

这是一个例子:

RewriteRule ^landing(/)?([0-9]+)?(/)?$ landing/index.php?intPage=$2

所以当有人去 /landing/3 时,它会加载 index.php 页面并将 intPage 参数传递为 3。

非常简单。

但是,我正在使用技术来跟踪 Google Analytics 引用,因此我需要在此 URL 上添加参数:

例如:

/landing/3?kt_type=ad&kt_st1=adwords&kt_st2=prize_a_us.en

问题是,我不知道如何检索附加在 URL 上的参数,因为 URL 已经被覆盖,现在我无法检索 kt_type、kt_st1 等。

知道如何让它成为可能,以便我仍然可以将参数附加到已经覆盖的 URL 上吗?

【问题讨论】:

    标签: .htaccess url-rewriting rewrite clean-urls


    【解决方案1】:

    使用QSA flag。将您的规则更改为:

    RewriteRule ^landing/?([0-9]+)?/?$ landing/index.php?intPage=$1 [L,NC,QSA]
    

    来自官方文档:

    QSA - 将原始请求 URL 中的任何查询字符串附加到任何 在重写目标中创建的查询字符串

    【讨论】:

    • 这里的 L,NC 是什么?
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 2020-03-18
    相关资源
    最近更新 更多