Php 如何在htaccess中检索特定的get数据并将其传递给重写规则

Php 如何在htaccess中检索特定的get数据并将其传递给重写规则,php,.htaccess,url-rewriting,rewrite,Php,.htaccess,Url Rewriting,Rewrite,我有一个单一的获取数据(affid),我想用.htaccess检索它,但我不知道怎么做。你能帮我吗 以下是链接示例: mysite.com/searchmembers?affid=1001 mysite.com/profle/123?affid=1002 mysite.com/videos/567?affid=1003 另一个可能出现问题的地方是,这些链接已经在.htaccess上重写了 RewriteRule ^searchmembers? index.php?task=searchMemb

我有一个单一的获取数据(affid),我想用.htaccess检索它,但我不知道怎么做。你能帮我吗

以下是链接示例:

mysite.com/searchmembers?affid=1001
mysite.com/profle/123?affid=1002
mysite.com/videos/567?affid=1003
另一个可能出现问题的地方是,这些链接已经在.htaccess上重写了

RewriteRule ^searchmembers? index.php?task=searchMembers
RewriteRule ^profile/(.*)? index.php?task=viewProfile&id=$1
RewriteRule ^videos? index.php?task=videos&id=$1
我只想检索affid并将其添加到如下链接:

RewriteRule ^searchmembers... index.php?task=searchMembers&affid=(data retrieved)
RewriteRule ^profile/(.*)... index.php?task=viewProfile&id=$1&affid=(data retrieved)
RewriteRule ^videos? index.php... task=videos&id=$1&affid=(data retrieved)

我知道我可以在htaccess上为每个链接添加它,但如果有更简单的方法,那么它将是一个很大的帮助。感谢您对我的回复

将其添加到web根目录中的
.htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^searchmembers$ index.php?task=searchMembers [QSA,NC,L]
RewriteRule ^profile/(.*)$ index.php?task=viewProfile&id=$1 [QSA,NC,L]
RewriteRule ^videos/(.*)$ index.php?task=videos&id=$1 [QSA,NC,L]

如果您只需要附加一个新的查询参数(如此处的
task
),则可以使用
[QSA]
(查询字符串附加)标志自动附加任何现有的查询参数。我还更正了您的
重写规则中使用的正则表达式。
的使用不正确。

您好。我不知道我会这么快得到正确答案。非常感谢你。但是除了添加[QSA]之外,还有其他方法可以影响mysite中的所有链接吗?顺便说一下,我很感激你的回答。非常感谢。我不确定我是否清楚地理解了您的意思,但除非您在没有
[QSA]
的情况下重写特定的URL,否则您不会丢失
附加的
。如果您的意思是一旦收到
affid
,就应该将其附加到页面中的所有链接中;将其保存在会话中,或者改用cookies。我想没有其他方法了。我最好用这个。非常感谢你!