mod_rewrite 显示 URL 更改,但我不明白为什么
我试图简单地将domain.net/abc 作为 /s2?alt_url=abc 传递到 Rails 应用程序,并且我不希望 URL 在浏览器中显示为已更改。我已经在这个问题上兜圈子很长时间了。我可以让重写工作(应用程序运行良好),但 URL 总是在浏览器中被替换。
RewriteEngine On
RewriteRule ^/([a-zA-Z0-9_-]+)$ /s2?alt_url=domain.net\%2F$1 [PT]
如果我不使用 [PT],那么我的最终规则将无法正确传递到 Rails 应用程序。我正在运行 Passenger 并根据 http:// 的讨论code.google.com/p/phusion-passenger/issues/detail?id=230 我必须使用 [PT] 并注意不要做任何其他疯狂的事情。所以我不确定为什么传递选项强制外部重定向,但这似乎是必要的。
有谁知道如何在不更改 Rails 应用程序的情况下避免 URL 更改?
任何帮助将不胜感激。 菲尔
I'm trying to simply get domain.net/abc to be passed to a Rails app as /s2?alt_url=abc and I don't want the URL to appear to have changed in the browser. I've been going around in circles with this for a long time now. I can get the rewrite to work (the app runs fine) but the URL is always swapped out in the browser.
RewriteEngine On
RewriteRule ^/([a-zA-Z0-9_-]+)$ /s2?alt_url=domain.net\%2F$1 [PT]
If I don't use [PT] then my final rule fails to pass correctly to the Rails app. I'm running Passenger and according to the discussion at http://code.google.com/p/phusion-passenger/issues/detail?id=230 I have to use [PT] and take care to not do anything else crazy. So I'm not sure why the pass through option forces an external redirect, but it seems to be necessary for this to work.
Does anybody know how I can avoid the URL changing without altering the Rails app?
Any help would be much appreciated.
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,您会得到一个外部重定向(HTTP 302 或类似的),并且您可以使用 [R] 强制执行该重定向。我认为你应该简单地删除[R]。
有关 R 标志的更多信息。
更新 Ẁ当我想到这一点时,更改域名(为http://domain.net/home< /a> 在这种情况下)始终是外部重定向。
我建议为更改域名和处理最终域名上的各种路径制定单独的规则。
You obviously get an external redirect (HTTP 302 or similar), and you force that with [R]. I think you should simply remove [R].
More about the R flag.
Update Ẁhen I think about it, changing domain names (to http://domain.net/home in this case) with always be an external redirect.
I suggest having separate rules for changing domain name and for handling various paths on the final domain name.
不熟悉 Rails,但是这个例子应该对你有帮助。此重写规则采用 / 后的任何内容(字母数字、_ 和 - )。 site.com/value
其中 ^([a-zA-Z0-9_-]+)$ 是一些正则表达式,我曾经在 url 之后获取任何内容,并将其放入 $1
这将使您的 url 保留为 site.com/value
编辑:我如何使用它的一个示例:grwl.it/kirbdee,它保留网址不变,但底层调用php 将 kirbdee 作为变量传递。
Not familiar with rails but, this example should help you. this rewrite rule takes anything (alphanumeric, _ , and - ) after the the / ie. site.com/value
Where ^([a-zA-Z0-9_-]+)$ is some regex I used to take anything after the url, and puts it in $1
This will leave your url as site.com/value
edit: an example of how I use this: grwl.it/kirbdee, it leaves the url as is but underlyingly calls a php passing in kirbdee as a variable.