[英]Using Apache mod_rewrite to move query parameters after /#
I need Apache to rewrite URLs by moving the HTTP query string from 我需要Apache通过从以下位置移动HTTP查询字符串来重写URL。
/?foo=bar
to 至
/#/?foo=bar
so that those query parameters can be picked up by Angular's $location.search()
. 以便那些查询参数可以由Angular的
$location.search()
。
I'd like this to work only on for the root path, /
, and not on any other paths such as /hello
. 我希望此方法仅适用于根路径
/
,而不适用于其他任何路径,如/hello
。
I have the following Location block on my Apache VirtualHost config: 我的Apache VirtualHost配置上具有以下Location块:
<Location />
RewriteEngine on
# Put a /# in front of the query string
RewriteCond "%{QUERY_STRING}" "^(.*)"
RewriteRule "/" "/#/?%1" [R=302,NE]
</Location>
which works for /
but it also rewrites: 适用于
/
但它也会重写:
/hello?foo=bar
to 至
/#/?foo=bar
ie it drops the path /hello
from the rewritten destination. 即,它从重写的目标位置删除路径
/hello
。 I'd like Apache to rewrite /hello?foo=bar
to /hello/#/?foo=bar
我希望Apache将
/hello?foo=bar
重写为/hello/#/?foo=bar
Using Angular html5 mode isn't possible because I have to support IE9 and under. 无法使用Angular html5模式,因为我必须支持IE9及以下版本。
Can anyone help me with a better RewriteRule that only works for /
? 谁能帮我一个只适用于
/
的更好的RewriteRule?
Thanks! 谢谢!
This seems to have done the trick: 这似乎可以解决问题:
<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.