.htaccess 指令与“DocumentRoot 更改”冲突+ “始终显示子域”
我进行了重写,将我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
^(.*)$
模式捕获当前 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:$1
with a variable, e.g.%{REQUEST_URI}