为什么我的子域名重定向到我的主要领域? [英] Why is my subdomain redirecting to my main domain?

查看:116
本文介绍了为什么我的子域名重定向到我的主要领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,基本上,我有一个子域, m.mydomain.com.au 虽然我每次访问它,我重定向到 WWW。 mydomain.com.au/m

例如,如果我试图去 m.mydomain.com.au/contact.php ,我是自动重定向到 WWW。 mydomain.com.au/m/contact.php

我从来没有尝试之前修改我的的.htaccess 文件,但我相信这是目前造成问题的原因。

所有帮助和建议,大大AP preciated。

下面是我的全的.htaccess 文件:

 选项+了FollowSymLinks

#使用mod_deflate模块,以COM preSS静态文件
< ifmodule mod_deflate.c>
<。(JS | CSS | ICO | TXT | HTM |全文| PHP)$filesmatch>
SetOutputFilter DEFLATE
< / filesmatch>
< / ifmodule>

#加快缓存
FileETag Mtime时光尺寸

#过期
ExpiresActive在
ExpiresDefault进入加366天

#的Expires头
< filesmatch。(ICO | PDF | FLV | JPG | JPEG | PNG | GIF | JS | CSS | SWF)$>
标题设定过期周六,2014年12月27日23:59:59 GMT
< / filesmatch>


RewriteEngine叙述上


的RewriteCond%{QUERY_STRING} base64_en code [^(] * \([^)] * \)[OR]
的RewriteCond%{QUERY_STRING}(小于|%3C)([^ s]的* S)+ CRIPT *。(大于|%3E)[NC,OR]
的RewriteCond%{QUERY_STRING} GLOBALS(= | \ [| \%[0-9A-Z] {0,2})[OR]
的RewriteCond%{QUERY_STRING} _ REQUEST(= | \ [| \%[0-9A-Z] {0,2})
重写规则。*的index.php [F]
的RewriteCond%{HTTP_HOST}!^ WWW \ .mydomain \ .COM \ .AU
重写规则^(。*)$ http://www.mydomain.com.au/$1 [R =永久,L]

#RewriteBase /


。重写规则*  -  [E = HTTP_AUTHORIZATION:%{HTTP:授权}]

的RewriteCond%{REQUEST_URI}!^ /指数\ .PHP

的RewriteCond%{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]

的RewriteCond%{} REQUEST_FILENAME!-f

的RewriteCond%{} REQUEST_FILENAME!-d

重写规则。*的index.php [L]
 

解决方案

假设这两个子域和主域名具有相同的文档根目录(因此使用相同htaccess文件),这是造成重定向规则:

 的RewriteCond%{HTTP_HOST}!^ WWW \ .mydomain \ .COM \ .AU
重写规则^(。*)$ http://www.mydomain.com.au/$1 [R =永久,L]
 

这基本上是说,如果访问的不可以 www.mydomain.com.au ,重定向到 HTTP ://www.mydomain.com.au/

您需要添加额外的检查,以便它不重定向你的子域名:

 的RewriteCond%{HTTP_HOST}!^ WWW \ .mydomain \ .COM \ .AU $ [NC]
的RewriteCond%{HTTP_HOST}!^ M \ .mydomain \ .COM \ .AU $ [NC]
重写规则^(。*)$ http://www.mydomain.com.au/$1 [R =永久,L]
 

或者只是重定向没有 WWW的域名

 的RewriteCond%{HTTP_HOST} ^ MYDOMAIN \ .COM \ .AU $ [NC]
重写规则^(。*)$ http://www.mydomain.com.au/$1 [R =永久,L]
 

So basically, I have a subdomain, m.mydomain.com.au although every time I visit it, I am redirected to www.mydomain.com.au/m.

For example, if I attempt to go to m.mydomain.com.au/contact.php, I am automatically redirected to www.mydomain.com.au/m/contact.php

I have never attempted to modify my .htaccess file before, but I believe it is causing the problem at the moment.

All help and suggestions is greatly appreciated.

Here is my full .htaccess file:

Options +FollowSymLinks

# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
<filesmatch ".(js|css|ico|txt|htm|html|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>


RewriteEngine On


RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com\.au
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=permanent,L]

#RewriteBase /


RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} !^/index\.php

RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php [L]

解决方案

Assuming that both your subdomain and main domain have the same document root (and thus use the same htaccess file), this is the rule that's causing the redirect:

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com\.au
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=permanent,L]

This essentially says, if the domain is not www.mydomain.com.au, redirect it to http://www.mydomain.com.au/.

You need to add an additional check so that it doesn't redirect your subdomain:

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com\.au$ [NC]
RewriteCond %{HTTP_HOST} !^m\.mydomain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=permanent,L]

Or only redirect the domain without the www.:

RewriteCond %{HTTP_HOST} ^mydomain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [R=permanent,L]

这篇关于为什么我的子域名重定向到我的主要领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆