删除www.仅在目录中

发布于 2024-11-19 11:29:43 字数 440 浏览 7 评论 0原文

我正在尝试删除名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-11-26 11:29:43

HTTP_HOST 将不包含您需要与重写规则本身匹配的正在访问的路径:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^dir\/(.*)$ http://example.com/dir/$1 [R=301,L]

The HTTP_HOST will not contain the path being accessed you need to match that in the rewrite rule itself:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^dir\/(.*)$ http://example.com/dir/$1 [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文