RewriteRule 将字符串添加到 URL 末尾

发布于 2024-10-02 18:17:21 字数 348 浏览 1 评论 0原文

这对我不起作用:

RewriteRule ^tags/[^?/] Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=%1 [QSA]

当我转到页面 www.mydomain.com/tags/tag1 时,它会将其重写为 www.mydomain.com/Templates/showpage.asp?DBID= 1&LNGID=2&TMID=133&FID=898&tag=

如何将“tag1”添加到 URL?

This is not working for me:

RewriteRule ^tags/[^?/] Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=%1 [QSA]

When I go to page www.mydomain.com/tags/tag1, it rewrites it to www.mydomain.com/Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=.

How do I add "tag1" to the URL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请叫√我孤独 2024-10-09 18:17:21

没有 ISAPI 经验,但我可能会尝试这样做:

RewriteRule ^tags/(\w+)/?$ Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=$1 [QSA]

本质上,您缺少的是用于捕获要用于代替 $1 的匹配标记的括号,

我放置了条件斜杠 (< code>/?) 在括号外,假设标签不应包含斜杠,但带或不带尾部斜杠的 URL 都是可接受的。

更新

如果您需要更自由地接受哪些字符作为标签,您可以使用类似 ^tags/([^/?]+)/?$ 的内容来允许所有字符(斜杠除外)和问号)正如 Pavel 的建议。

No experience with ISAPI, but I would probably try this:

RewriteRule ^tags/(\w+)/?$ Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=$1 [QSA]

Essentially, what you're missing is the brackets to capture the matching tag that is to be used in place of $1

I placed the conditional slash (/?) outside the bracket with the assumption that tags shouldn't contain the slash but URLs with or without the trailing slash are acceptable.

Update

If you need to be more liberal with what characters you accept as tags, you can use something like ^tags/([^/?]+)/?$ to allow all characters (apart from slash and question mark) as suggested by Pavel.

奢华的一滴泪 2024-10-09 18:17:21

试试这个:

RewriteRule ^tags/([^?/]+) Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=%1 [QSA]

Try this:

RewriteRule ^tags/([^?/]+) Templates/showpage.asp?DBID=1&LNGID=2&TMID=133&FID=898&tag=%1 [QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文