【问题标题】:How to deal with "#" in a query string in mod_rewrite?如何处理 mod_rewrite 中查询字符串中的“#”?
【发布时间】:2010-12-12 12:28:48
【问题描述】:

我向this question 询问了关于将旧的“丑陋”链接重写为 seo 友好的链接。

我需要在某些网址中的“尖锐”符号之后“提取”一些信息。我已经为其创建了一个正则表达式,但它无法正常工作。

在我提出问题后,我为此网址创建了这个逻辑,例如,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:

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 代码正确重定向)。

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

【问题讨论】:

    标签: mod-rewrite seo


    【解决方案1】:

    锚信息(以# 开头的部分)从未真正发送到服务器。它完全由浏览器处理,因此您无法使用 mod_rewrite 触摸它(也无法通过服务器端脚本语言访问它)。唯一能看到它的是浏览器和客户端脚本(如 Javascript)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-04
      相关资源
      最近更新 更多