简体   繁体   English

使用Apache mod_rewrite在/#之后移动查询参数

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

相关问题 在将AngularJS与Apache 2一起使用时,为什么需要mod_rewrite模块? - Why do we need mod_rewrite module when using AngularJS with Apache 2? 如何在.htaccess中使用mod_rewrite / RewriteRule将所有“ _escaped_fragment_” URL重定向到静态snpashot html文件夹以处理AngularJS SEO - How to mod_rewrite / RewriteRule in .htaccess to redirect all “_escaped_fragment_” url to static snpashot html folder to handle AngularJS SEO 在同一台计算机上使用多个域的Angular网站的Apache重写规则 - Apache rewrite rules for Angular site using multiple domains on same machine 使用ngRoute移至其他页面时,html中的Angular参数未知 - When move to other page by using ngRoute, Angular parameters are unknown in html 使用查询字符串参数过滤数据 - Filter data using query string parameters Apache重写条件以进行Ajax爬网 - Apache rewrite condition for ajax crawling 如何在AngularJS中刷新页面后保留路径和查询字符串参数 - How to preserve path and query string parameters after page refresh in AngularJS 使用angular js单击另一个div后的div移动 - Div move after click on another div using angular js 服务器端310如何在图章服务器中重定向,mod重写? - How to do server end 310 redirect, mod rewrite in a stamplay server? AngularJS和Apache重写不适用于子文件夹 - Angularjs and apache rewrite doesn't work on subfolder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM