.htaccess 用问号重写 URL

.htaccess rewrite URL with question mark

我有一个名为“Post Affiliate Pro”的程序给我的 htaccess 代码,看起来像这样

# Start Post Affiliate SEO Code----

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule .? - [S=4]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid= [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=&a_bid= [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=&a_bid=&chan= [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=&a_bid=&chan=&data1= [R=301,L]

RewriteRule ^?coupon-code=([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=&a_bid=&chan=&data1=&data2= [R=301,L]

# End of Post Affiliate SEO Code

这破坏了我的网站,因为我尝试重定向的 URL 开头有一个查询字符串,就像这样 https://example.com/?coupon-code=PGZ

我知道我需要使用 QUERYSTRING 以某种方式修改它,但我不知道具体要做什么。谁能帮我修改这个 htaccess 代码,以免它破坏我的网站?

根据您显示的 attempts/samples,请尝试在您的 .htaccess 文件中遵循规则文件。请确保在测试您的 URL 之前清除您的浏览器缓存。

##Making RewriteEngine ON here.
RewriteEngine On
##For existing pages rules here..
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [S=4]

##For handling 4 parameters handling rules here.
RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3&data1=%4 [R=301,L]

##For handling 3 parameters handling rules here.    
RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3 [R=301,L]

##For handling 2 parameters handling rules here.
RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/?$ [NC]
RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2 [R=301,L]

##For handling 1 parameters handling rules here.
RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/?$ [NC]
RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1 [R=301,L]
    
##For handling 5 parameters handling rules here.
RewriteCond %{QUERY_STRING} ^coupon-code=([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ [NC]
RewriteRule ^/?$ https://example.postaffiliatepro.com/scripts/l5zhexygnc?a_aid=%1&a_bid=%2&chan=%3&data1=%4&data2=%5 [R=301,L]

# End of Post Affiliate SEO Code