双斜杠apache配置
我正在部署一个 ror 应用程序,现在我必须重写 url (在 apache 中)以
- 在 url 中添加前缀 www 在 url 中
- 添加 / 到 url 的末尾
所以我采用了以下方法:
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^foo\.com
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L]
问题是它附加了两个我的网址的尾部斜杠 因此,例如资源/问题/询问正在变成:
http://foo.com//question/ask
我尝试在所有重写规则之前添加以下规则以尝试删除双//:
RewriteCond %{REQUEST_URI} ^//
RewriteRule ([^/]*)/+(.*) http://www.foo.com/$1/$2 [R=301,L]
但它不起作用..有任何想法可以撕掉所有额外的“//”添加到网址?
i'm deploying a ror application and now i have to rewrite the url (in apache) to
- add a prefix www to the url
- add / to the end of the url
So i took the following approach:
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^foo\.com
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L]
The problem is that it is appending two trailing slash to my url
So for example a resource /question/ask are becoming:
http://foo.com//question/ask
I tried to add the following Rule before all my Rewrite rules to try to remove the double //:
RewriteCond %{REQUEST_URI} ^//
RewriteRule ([^/]*)/+(.*) http://www.foo.com/$1/$2 [R=301,L]
but it didnt work.. any idea to rip off all extras "//" added to the url?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$1
将在开头包含一个/
。你可能想要The
$1
will include a/
at the beginning. You probably want