需要帮忙。重写规则不适用于 /?

need help. rewriterule not working with /?

我的 URL 是

http://example.com/?aff_id=username 

我希望它像

http://example.com/?ap_id=username

我已经尝试了所有可能的方法,但没有运气。如果我删除 ?(问号),它会起作用,但我想在我的 URL 中使用 ?。我知道这是一个正则表达式,所以我试图逃避它,但没有成功。

您可以在 /.htaccess 文件中使用以下内容:

RewriteEngine on
RewriteCond %{QUERY_STRING} aff_id=([\w]+) [NC]
RewriteRule ^$ /?ap_id=%1 [R,L]

如果您想永久重定向,请将 R 更改为 R=301