【发布时间】:2021-01-19 00:16:45
【问题描述】:
我的目标是将任何不以特定符号 ("#") 开头的 URL 重定向到不同的网站。 我正在使用 Firebase 托管,并且已经在重定向中尝试了 Regex 函数来实现这一点。我在重定向上关注了这个 firebase documentation,但是因为我是正则表达式的新手,所以我认为我的错误可能是我的正则表达式代码。
我的目标:
- mydomain.com/anyNotStartingWith# => otherdomain.com/anyNotStartingWith#
- mydomain.com/#any => mydomain.com/#any
我的代码:
{
"hosting": {
...
"redirects": [
{
"regex": "/^[^#]:params*",
"destination": "otherdomain.com/:params",
"type": 301
}
],
...
}
}
【问题讨论】:
-
试试
"regex": "/(?P<params>[^/#][^/]*)",或"regex": "/(?P<params>[^/#].*)" -
@WiktorStribiżew 感谢您的帮助,两者都有效!有没有办法在这个表达式中添加一些东西来检查 URL 是否以 .js 结尾并且也不允许这样做。这样 mydomain.com/any.js 也不会被重定向。
标签: regex firebase redirect firebase-hosting