301的.htaccess重写规则QUERY_STRING [英] 301 Htaccess RewriteRule Query_String

查看:198
本文介绍了301的.htaccess重写规则QUERY_STRING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已经试过:在最后几个小时我试过很多的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_STRING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆