删除www.仅在目录中
我正在尝试删除名为 dir 的单个目录的 www.
(例如)。我需要能够从该目录中的 .htaccess
文件执行此操作。 (我没有 root 访问权限。)知道如何进行这项工作吗?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com/dir$ [NC]
RewriteRule ^(.*)$ http://example.com/dir$1 [R=301,L]
更新——解决方案:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/dir/$1 [R=301,L]
I'm trying to remove the www.
for a single directory called dir (for example). I need to be able to do this from the .htaccess
file in that directory. (I don't have root access.) Any idea how to make this work?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com/dir$ [NC]
RewriteRule ^(.*)$ http://example.com/dir$1 [R=301,L]
Update—the solution:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/dir/$1 [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HTTP_HOST 将不包含您需要与重写规则本身匹配的正在访问的路径:
The HTTP_HOST will not contain the path being accessed you need to match that in the rewrite rule itself: