簡體   English   中英

使用Apache mod_rewrite在/#之后移動查詢參數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM