【发布时间】:2021-02-09 05:22:21
【问题描述】:
我尝试了很多答案,但似乎都没有。
我想要什么?
1). 我想重定向这个(如果它包含参数 from 和 to 并且它们都不是空):
https://arc.abc.com/mconvertar.php?from=gbp&to=jpy
到
https://arc.abc.com/gbpjpy/
如你所见,我们结合了 from & to 的值
2). 还有 this(如果它包含参数 x 以及 from 和 to >):
https://arc.abc.com/mconvertar.php?from=gbp&to=jpy&x=13
到
https://arc.abc.com/gbpjpy/x=13
如您所见,13 与上面的 url 相同。
3). 如果 x 为空,则:
https://arc.abc.com/mconvertar.php?from=gbp&to=jpy&x=
到
https://arc.abc.com/gbpjpy/x=1
如您所见,我们将 x 值默认设置为 1
我尝试了什么?
RewriteCond %{QUERY_STRING} (^|&)from=[^&\s]&to=[^&\s]&x=[0-9]
RewriteRule ^(.*)$ https://arc.abc.com/gbpjpy/x=%3 [R=301,L]
RewriteCond %{QUERY_STRING} !(^|&)x=($|&)
RewriteRule ^(.*)$ https://arc.abc.com/gbpjpy/x=1 [R=301,L]
RewriteRule ^([^/]*)([^/]*)/([^/]*)\.html$ /mconvertar.php?from=$1&to=$2 [L]
非常感谢您的帮助,花了很多时间
【问题讨论】:
标签: regex apache .htaccess redirect