301的.htaccess重写规则QUERY

编程入门 行业动态 更新时间:2024-10-19 02:17:31
本文介绍了301的.htaccess重写规则QUERY_STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

问题:访客打开URL的的 website/?i=133r534|213213|12312312 的,但此URL不再有效他们需要转发为的 website/#Videos:133r534|213213|12312312 的

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

我已经试过:在最后几个小时我试过很多的mod_rewrite(的.htaccess)使用QUERY_STRING规则,都失败了。在这个话题的最后一条消息显示了该问题的解决方案,但会是什么在我的处境规则。

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 :)!

推荐答案

下面将处理您展示的简单情况。你需要添加额外的逻辑,如果你需要,以便在之前的查询字符串或文件名等参数?

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?

  • 在重写规则不看的查询字符串,所以你必须使用的RewriteCond评估QUERY_STRING变量和捕捉你以后需要的部分(通过参考%1)
  • 散列字符(#)通常逃​​脱,你必须指定[NE]标志
  • 的结尾?在替换字符串必须燮preSS原来的查询字符串

我测试了在Apache 2.2。

I tested this on Apache 2.2.

更多推荐

301的.htaccess重写规则QUERY

本文发布于:2023-11-01 12:51:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   规则   htaccess   QUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!