如何处理“#"在mod_rewrite的查询字符串中? [英] How to deal with "#" in a query string in mod_rewrite?

查看:42
本文介绍了如何处理“#"在mod_rewrite的查询字符串中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了这个问题将旧的丑陋"链接重写为seo友好链接.

I asked this question about rewriting old "ugly" links into seo friendly ones.

我需要在某些URL中的尖锐"符号后提取"一些信息.我已经为其创建了一个正则表达式,但是看不到它起作用.

I need to "extract" some information after the "sharp" symbol in some urls. I've created a regular expression to it but it can't seen to work.

我的问题之后,我为此URL创建了此逻辑,例如script.php?mode=full&id=23:

After my question, I created this logic for this url for example, script.php?mode=full&id=23:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /script\.php\?mode=full&id=([0-9]+)\ HTTP/
RewriteRule ^script\.php$ fix_old_urls.php?phpfile=script2&id=%1 [NC,L]

但是我正在使用旧版应用程序,因此我需要在某些页面的尖符号后提取值,例如url script.php?mode=full#23:

But I'm working in a legacy application, and I need to extract the value after the sharp symbol in some pages, in the example url script.php?mode=full#23:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /script\.php\?mode=list\#([0-9]+)\ HTTP/
RewriteRule ^script\.php$ fix_old_urls.php?phpfile=script&id=%1 [NC,L]

(在fix_old_urls中,我正确地使用301代码重定向).

(in fix_old_urls I properly redirect with a 301 code).

第一个有效,但第二个无效.在我看来,两者都具有相同的逻辑.我在做什么错了?

The first one works, but not the second. To me it looks like it`s the same logic in both. What am I'm doing wrong?

推荐答案

定位信息(以#开头的部分)实际上从未发送到服务器.它完全由浏览器处理,因此您无法使用mod_rewrite对其进行操作(也无法通过服务器端脚本语言对其进行访问).唯一可以看到的是浏览器和客户端脚本(例如Javascript).

Anchor information (the part starting with the #) is never actually sent to the server. It's handled completely by the browser, and thus you can't touch it with mod_rewrite (nor can you access it via server-side scripting languages). The only things that can see it are the browser and client-side scripts (like Javascript).

这篇关于如何处理“#"在mod_rewrite的查询字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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