剥离 www. from 域适用于主站点,但不适用于子域
我目前的 .htaccess 文件如下:
ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
当我访问我的主站点:www.site.com 时,www.被剥离,因为它应该是,一切工作正常。
当我以正确的格式访问子域(http://sub.site.com)时,一切正常。
当用户输入 www 时就会出现问题。作为子域的一部分,因此: http://www.sub.site.com 不会删除 www。而是重定向到媒体寺庙托管的“子域不存在”页面(顺便说一句,非常烦人)。
有什么建议吗?
I currently have my .htaccess file as the following:
ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]
when I visit my primary site at: www.site.com, the www. is stripped as it should be and all works fine.
When I visit a subdomain in proper format (http://sub.site.com) everythign works fine.
The issue comes when a user would enter www. as part of a subdomain so:
http://www.sub.site.com does not strip the www. and instead redirects to the Media temple hosted "sub-domain does not exist" page (INCREDIBLY ANNOYING by the way).
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改这些行:
至:
Change these lines:
To:
我相信我必须“欺骗”系统,但找到了一种工作方法:
我首先必须在我的子域中创建一个 vhost.conf 文件:
重置 Plesk 和我的 Apache 服务器后,我还在我的子域中添加了通配符 DNS 记录,如下所示:
这似乎暂时解决了我的问题,但仍然无法弄清楚为什么前者不起作用。
I believe I had to "trick" the system but found a working method:
I first had to create a vhost.conf file within my subdomain with:
After resetting Plesk and my Apache server, I also added a wildcard DNS record to my subdomain as:
This seems to have resolved my issue for now though still can't figure out why the former did not work.