需要正则表达式帮助将 URL 重写查询字符串为友好的 URL
我更新了网站 CMS,URL 格式已更改。以前我有 URL /blog.aspx?Year=XXXX&Month=YY 我现在有 /blog/XXXX/YY
有人可以帮我为此创建一个正则表达式?
两个额外的注意事项:
- 它还必须支持简单的年份 (/blog.aspx?Year=XXX),
- 旧的月份 url 仅使用 1 位数表示个位数月份 (/blog.aspx? Year=2009&Month=2 而不是 Month=02)
这是我想到的:
/blog.aspx[?]Year=([0-9]{4})([&]?)(Month=)?([0-9]*)
我似乎无法让它工作,因为我仍然收到 404页面当我访问上述网址之一时。
I updated my website CMS and the URL formats have changed. Where previously I had the URL /blog.aspx?Year=XXXX&Month=YY I now have /blog/XXXX/YY
Can someone help me create a regex for this?
Two additional notes:
- it has to also support simply the year (/blog.aspx?Year=XXX)
- the old Month urls use only 1 digit for single digit months (/blog.aspx?Year=2009&Month=2 instead of Month=02)
Here is what I came up with:
/blog.aspx[?]Year=([0-9]{4})([&]?)(Month=)?([0-9]*)
I can't seem to get it to work, as I still get a 404 on the page when I go to one of the above URLs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可行吗?
与这些输入一起使用时,
有这个
(?>>blabla|moomoo)
语法。如果找不到
blabla
匹配,它将匹配moomoo
虽然我怀疑这里的正则表达式不是根本问题,但什么 CMS 处理重定向?
Is this workable?
works with these input
there is this
(?>blabla|moomoo)
syntax.If it cant find
blabla
match, it will matchmoomoo
Though i suspect regex here is not the root problem, what CMS handles the redirect?