![](/img/trans.png)
[英]Why do we need mod_rewrite module when using AngularJS with Apache 2?
[英]Using Apache mod_rewrite to move query parameters after /#
我需要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?
谢谢!
这似乎可以解决问题:
<Location />
RewriteEngine on
# Put a /# in front of the query string
RewriteCond %{REQUEST_URI} ^/$
RewriteCond "%{QUERY_STRING}" "^(.+)"
RewriteRule "/" "/#/?%1" [R=302,NE]
</Location>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.