波形符的重写规则
我正在尝试对波形符 URL 进行以下重写:
RewriteRule ^/?~folder/(.*) http://whatever.com/$1 [R=302,L]
我希望任何带有 whatever.com/~folder/something
的链接都变为 whatever.com/something
。
如果我的情况排除了波形符(也尝试转义它, \~
),则上述重写规则似乎有效,但使用波形符时,它不会执行重写。
我是否需要调整更广泛的配置设置才能在我的情况下启用重写?我通常理解 ~folder
指的是用户的主目录,但我不知道它如何发挥作用或可以根据我的情况进行调整。
I am trying to do the following rewrite of tilde URLs:
RewriteRule ^/?~folder/(.*) http://whatever.com/$1 [R=302,L]
I want any links with whatever.com/~folder/something
to become whatever.com/something
.
It seems that the above rewrite rule works if my situation excluded the tilde (also tried escaping it, \~
), but with the tilde it does not perform the rewrite.
Is there a broader configuration setting I need to adjust to enable rewriting in my situation? I understand normally ~folder
refers to a user's home directory, but I don't know how that comes into play or can be adjusted in my situation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我能够修复对 http://domain.ext/~blog/file.html 在 webroot (public_html) 处使用此 .htaccess 规则:
来自:http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-htaccess.phtml
I was able to fix any hits to http://domain.ext/~blog/file.html with this .htaccess rule at webroot (public_html):
From: http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-htaccess.phtml
正如您提到的,它可能与使用
mod_userdir
相关。请检查您的 apache 配置是否已激活,并查看禁用它是否可以解决问题。http://httpd.apache.org/docs/2.2/mod/mod_userdir.html
It is probably linked to the use
mod_userdir
as you mention. Please check in your apache configuration if it is now activated and see if disabling it fixes the issue.http://httpd.apache.org/docs/2.2/mod/mod_userdir.html
我使用此规则重定向以波浪号开头的所有内容
来自 @Sigg3.net 源: http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-htaccess.phtml
I use this rule to redirect everything which starts with tilde
From @Sigg3.net source : http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-htaccess.phtml