第301章

发布于 2024-09-25 15:41:52 字数 423 浏览 1 评论 0原文

问题:访问者打开网址 website.com/?i=133r534|213213|12312312,但该网址不再有效,他们需要转发到 website.com/#Videos:133r534|213213|12312312

我尝试过的: 在过去的几个小时里,我尝试了很多mod_rewrite(.htaccess)规则与使用Query_String,全部失败。 此主题中的最后一条消息显示了此问题的解决方案,但是会是什么我的情况的规则。

我很好奇你会如何解决这个问题:)!

Problem: Visitors open the url website.com/?i=133r534|213213|12312312 but this url isn't valid anymore and they need to be forwarded to website.com/#Videos:133r534|213213|12312312

What I've tried: During the last hours I tried many mod_rewrite (.htaccess) rules with using Query_String, all failed. The last message in this topic shows a solution for this problem, but what would be the rule in my situation.

I'm very curious how you would solve this problem :)!

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

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

发布评论

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

评论(1

微暖i 2024-10-02 15:41:52

下面将处理您展示的简单情况。如果您需要在查询字符串或 ? 之前的文件名中允许使用其他参数,则需要添加其他逻辑。

RewriteEngine On
RewriteCond %{QUERY_STRING} ^i=(.*)
RewriteRule ^.*  /#Video:%1? [NE,R=permanent]

为什么这很棘手?

  • RewriteRule 不查看查询字符串,因此您必须使用 RewriteCond 来计算 QUERY_STRING 变量并捕获稍后需要的部分(通过 %1 引用)
  • 哈希字符 (#) 通常会被转义,您必须指定[NE] 标志
  • 尾随 ?需要使用替换字符串来抑制原始查询字符串,

我在 Apache 2.2 上对此进行了测试。

The following will handle the simple case you show. You'll need to add additional logic if you need to allow for other parameters in the query string or file names before the ?.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^i=(.*)
RewriteRule ^.*  /#Video:%1? [NE,R=permanent]

Why is this tricky?

  • RewriteRule doesn't look at the query string, so you have to use RewriteCond to evaluate the QUERY_STRING variable and capture the part you'll need later (referenced via %1)
  • the hash character (#) is normally escaped, you must specify the [NE] flag
  • The trailing ? on the substitution string is required to suppress the original query string

I tested this on Apache 2.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文