GET variable after mod_rewrite

夙愿已清 提交于 2020-01-11 06:50:11

问题


I have a set of product pages that obey the following htaccess rule:

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_URI} ^/([0-9]+)\-(.+)\.html
RewriteRule ^(.*)$ /product/index.php?prod=%1-%2 [L]

Which rewrites them to: example.com/123-1234.html.

My problem is that I can no longer pass additional $_GET variables to the page - IE: example.com/123-1234.html?coupon=something123.

Is there any way to do this?


回答1:


Your looking for QSA, Query String Append

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_URI} ^/([0-9]+)\-(.+)\.html
RewriteRule ^(.*)$ /product/index.php?prod=%1-%2 [L,QSA]



回答2:


Add the QSA flag to pass along existing query string params

RewriteRule . /product/index.php?prod=%1-%2 [QSA,L]

Also edited match as . and ^.*$ are equivalent in this case



来源:https://stackoverflow.com/questions/8228793/get-variable-after-mod-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!