【问题标题】:mod rewrite to remove facebook query stringmod重写以删除facebook查询字符串
【发布时间】:2012-09-25 14:36:37
【问题描述】:

我的查询字符串无法正常工作..请帮助... 我有以下网址: http://betatest.bracknell-forest.gov.uk/help?fb_action_ids=372043216205703&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582

(抱歉,该页面将不可用,因为它是一个测试内部域链接)

我想要以下网址: http://betatest.bracknell-forest.gov.uk/help

我收到一条浏览器消息,提示“系统找不到指定的文件。” 我知道这是因为我已经进行了 mod 重写以从页面名称中删除 .htm 以返回干净的 url,但我不知道我需要做什么来接受干净的 url 并返回页面。
这是我的模组重写代码:

RewriteRule ^/([\w]+)$ /$1.htm [I,L] #Any bare URL will get rewritten to a URL with .htm appended
RedirectRule ^/(.+)\.(htm)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

RewriteCond %{QUERY_STRING} ^fb_action_ids=(.)$ #if the query string contains fb_action_ids
RewriteCond %{QUERY_STRING} !="" #if there is a query string
RewriteRule ^(.*) $1? [R=301,L]

我认为这是因为我使用了两次 R=301 但不知道我需要使用什么作为替代。

如果我将 help?fb_action_ids.... 中的 .htm 附加到 help.htm?fb_action_ids.... 这将返回所需的页面,但我需要返回未附加 url 的页面名称。

非常感谢您提前提供的任何帮助。

【问题讨论】:

  • 有人可以帮忙吗?

标签: facebook mod-rewrite url-rewriting iis-6 iirf


【解决方案1】:

查看 iirf 帮助页面后确定,以下内容将删除所有查询字符串并显示干净的 url:

RewriteRule ^/(.+)\?(.+)&(.+)\.(htm)$  /$1    
RewriteRule ^/(.+)\?(.+)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

# Any bare URL will get rewritten to a URL with .htm appended
RewriteRule ^/([\w]+)$ /$1.htm [I,L]
RedirectRule ^/(.+)\.(htm)$       http://betatest.bracknell-forest.gov.uk/$1 [R=301]

iirf 需要对正则表达式有所了解,并且它与 mod_rewite 之间似乎存在细微差别。非常感谢提供的所有帮助。

【讨论】:

    【解决方案2】:

    这两行就可以了。我已经测试过了。

    RewriteCond %{QUERY_STRING} fb_action_ids
    RewriteRule ^(.*)$ $1? [R=301]
    

    如果您有 abc,格式如下的 URL:"abc?fb_action_ids......" 将被重定向到 "abc.htm" .htm

    但是,您可以在 http.conf 中关闭 MultiView,如果将被重定向到确切的“abc”文件。

    【讨论】:

    • 非常感谢您的回复-我开始认为那里没有人...我不仅需要帮助.htm,还需要整个站点。所以我需要一个适用于 pagename.htm 的重定向,其中 pagename 是页面的名称,所以...betatest.bracknell-forest.gov.uk/… 变为 betatest.bracknell-forest.gov.uk/pagenamebetatest.bracknell-forest.gov.uk/pagename.htm - 再次感谢您的回复
    • 好的,我已经编辑了上面的答案。它对我有用,但我不知道谁给了我一个减号。
    • 嗨本克。我尝试了上述方法并在 Firefox 中收到以下消息:页面未正确重定向。 Firefox 检测到服务器正在以永远不会完成的方式重定向对该地址的请求。我注意到网址已更改为betatest.bracknell-forest.gov.uk/…?????????????????????? - 添加?我认为它是从 1 美元获得的符号? - 不确定它是否有任何区别,但我在 Windows 服务器上的 IIS6 中使用 iirf。
    • 如果去掉“?”会怎样?我在apache上测试过,没问题。
    • 我刚试过没有 ?它会得到相同的 Firefox 消息,但没有 ???????????????在网址中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2015-08-20
    • 2011-03-02
    相关资源
    最近更新 更多