【问题标题】:Using Apache mod_rewrite to move query parameters after /#使用 Apache mod_rewrite 在 /# 之后移动查询参数
【发布时间】:2016-01-25 20:18:56
【问题描述】:

我需要 Apache 通过移动 HTTP 查询字符串来重写 URL

/?foo=bar

/#/?foo=bar

以便 Angular 的 $location.search() 可以获取这些查询参数。

我希望这仅适用于根路径 /,而不适用于任何其他路径,例如 /hello

我的 Apache VirtualHost 配置中有以下 Location 块:

<Location />
  RewriteEngine on
  # Put a /# in front of the query string
  RewriteCond "%{QUERY_STRING}" "^(.*)"
  RewriteRule "/" "/#/?%1" [R=302,NE]
</Location>

适用于/,但它也会重写:

/hello?foo=bar

/#/?foo=bar

即它从重写的目标中删除路径/hello。我希望 Apache 将 /hello?foo=bar 重写为 /hello/#/?foo=bar

无法使用 Angular html5 模式,因为我必须支持 IE9 及以下。

谁能帮助我更好的 RewriteRule 只适用于/

谢谢!

【问题讨论】:

    标签: angularjs apache .htaccess mod-rewrite


    【解决方案1】:

    这似乎成功了:

    <Location />
      RewriteEngine on
      # Put a /# in front of the query string
      RewriteCond %{REQUEST_URI} ^/$
      RewriteCond "%{QUERY_STRING}" "^(.+)"
      RewriteRule "/" "/#/?%1" [R=302,NE]
    </Location>
    

    【讨论】:

      猜你喜欢
      • 2012-11-07
      • 2012-08-30
      • 2014-07-27
      • 2011-07-16
      • 1970-01-01
      • 2010-12-02
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多