【发布时间】:2020-10-23 08:37:49
【问题描述】:
我有 .htaccess 问题,其中 url 在路由参数中,但我想将其转换为查询字符串格式。
当前路径是:http://localhost:4200/act/sso/app/2040/token/7d2f-4ddd-924f-3fd36572/address/chd/city/chd/state/chd
我想将其转换为:http://localhost:4200/act/sso?app=2040&token=7d2f-4ddd-924f-3fd36572&address=chd&city=chd&state=chd
我在下面写了 .htaccess 规则。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^act/sso/app/32/token/([^/]*)/address/([^/]*)/city/([^/]*)/state/([^/]*)
RewriteRule ^act/sso/app/32/token/([^/]*)/address/([^/]*)/city/([^/]*)/state/([^/]*) act/sso?appID=32&mfaToken=$1&address=$2&city=$3&state=$4 [R=301,L]
我的问题是当我们获取可选参数值时,我的路由规则不匹配。
见下面的例子。
http://localhost:4200/act/sso/app/2040/token/7d2f-4ddd-924f-3fd36572/address//city//state/chd
http://localhost:4200/act/sso/app/2040/token/7d2f-4ddd-924f-3fd36572/address/chd/city//state/chd
http://localhost:4200/act/sso/app/2040/token/7d2f-4ddd-924f-3fd36572/address/chd/city/chd/state/
请帮忙。
【问题讨论】: