【发布时间】: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