如何停止.htaccess将子域重定向到主站点? [英] How can I stop .htaccess redirecting a subdomain to the main site?
问题描述
我有一个.htaccess问题。基本上,我的.htaccess会将我新创建的子域重定向到主站点,但我不希望这样做。假设我的域名为 www.beans.com,子域为 shop.beans.com,该域位于<$ c $下的 public_html
文件夹中c> / shop / 。这是.htaccess文件:
I have a .htaccess question. Basically my .htaccess is redirecting my newly created sub domain, to the main site, and I don't want it to do so. Let's assume my domain is called 'www.beans.com', and the subdomain is 'shop.beans.com', which is in the public_html
folder under /shop/
. Here is the .htaccess:
DirectoryIndex index.php enmain.php
ErrorDocument 404 /404.html
## EXPIRES CACHING ##
ExpiresActive On
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/ico "access plus 1 year"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType text/xml "access plus 2 hours"
ExpiresDefault "access plus 1 hour"
## EXPIRES CACHING ##
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.beans.com$ [NC]
RewriteRule ^(.*)$ http://www.beans.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.beans.com/$1 [R=301,L]
# Start CloudFlare:beans.com rewrite. Do not Edit
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beans.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# End CloudFlare rewrite.
因此,总而言之,我想当我浏览到'shop.beans.com'时,不要重定向到 www.beans.com(当前正在发生)。
So in summary, I would like when I browse to 'shop.beans.com' not to be redirected to 'www.beans.com' (which currently happening).
我该怎么办?
推荐答案
首先,您有2条规则做同样的事情,即添加 www。
。
First thing you have 2 rules doing same thing i.e. adding www.
.
1-删除此规则:
RewriteCond %{HTTP_HOST} !^www.beans.com$ [NC]
RewriteRule ^(.*)$ http://www.beans.com/$1 [L,R=301]
2-然后更改最后一个规则,如下所示:
2 - Then change last rule like this:
RewriteCond %{HTTP_HOST} ^beans\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
这篇关于如何停止.htaccess将子域重定向到主站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!