![](/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.