.htaccess 指令与“DocumentRoot 更改”冲突+ “始终显示子域”

发布于 2024-10-07 17:41:47 字数 628 浏览 0 评论 0原文

我进行了重写,将我的 DocumentRoot 从 /public_html 更改为 /public_html/MAIN 并且效果很好。

RewriteRule ^$ /MAIN/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/MAIN/
RewriteRule ^(.*)$ /MAIN/$1

现在,如果我尝试添加以下指令以始终显示 www 子域,则它不再正常运行...

RewriteCond %{http_host} ^domain.com [nc]  
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

访问 http://domain.com/ 会导致重写到 http://www.domain.com/MAIN/ 这不是我想要的。 我不希望 MAIN 子目录可见。

我缺少什么?

I have a rewrite that changes my DocumentRoot from /public_html to /public_html/MAIN and it works great.

RewriteRule ^$ /MAIN/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/MAIN/
RewriteRule ^(.*)$ /MAIN/$1

Now If I try to add the following instruction to always show the www subdomain, it no longer behaves properly...

RewriteCond %{http_host} ^domain.com [nc]  
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Visiting http://domain.com/ causes a rewrite to http://www.domain.com/MAIN/ which is not what I want. I do not want the MAIN subdirectory to be visible.

What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

猥琐帝 2024-10-14 17:41:47

^(.*)$ 模式捕获当前 URI,无论它是在地址栏中还是内部重定向。这些解决方案之一应该有效:

  • 首先放置子域重定向
  • $1 替换为变量,例如 %{REQUEST_URI}

The ^(.*)$ pattern captures the current URI, no matter it's in the location bar or it's an internal redirection. One of these solutions should work:

  • Put the subdomain redirection first
  • Replace $1 with a variable, e.g. %{REQUEST_URI}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文