RewriteCond fetch array parameters from Query_String and convert into path while retaining the remaining parameters

喜你入骨 提交于 2020-06-17 03:47:45

问题


How to allow few parameters to continue to be redirected while one paramter which is an array to be converted into a string in the url path

example: param1[]=apple&price=1,10 should become /apple/?price=1,10

Orginal url: example.com/path1/?param1[]=apple&param2=1,100
Expected redirection: example.com/path1/apple/?param2=1,100

Orginal url: example.com/path1/path2/?param[]=apple&param2=1,100&param3=yes
Expected redirect: example.com/path1/path2/apple/?param2=1,100&param3=yes

回答1:


You may use this redirect rule that will handle param1[]= query parameter anywhere:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?param1\[\]=([^&]*)(?:&(.*))?$ [NC]
RewriteRule ^(.*?)/?$ /$1/%2?%1%3 [R=301,NE,L]


来源:https://stackoverflow.com/questions/61133237/rewritecond-fetch-array-parameters-from-query-string-and-convert-into-path-while

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