.htaccess将url从路由参数转换为带有空白参数值的查询字符串

时间:2020-10-23 08:37:49

标签: angular apache .htaccess

我遇到了.htaccess问题,其中url在route参数中,但是我想将其转换为查询字符串格式。

当前路径为:
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/

请对此提供帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试按照显示的示例进行以下操作,编写和测试吗?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/act/sso/app/([0-9]+)/token/([^/]*)/address/([^/]*)/city/([^/]*)/state/([^/]*)$
RewriteRule ^.*$ /act/sso?app=%1&token=%2&address=%3&city=%4=state=%5 [L,NE,NC,QSA]
相关问题