htaccess的子域名重定向问题 [英] .htaccess subdomain redirect problem

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

问题描述

我有一个网站,让我们说 www.example.com ,我有一个子域 something.example.com

I have a website let's say www.example.com and I have a subdomain something.example.com

这两个主要领域和子域名都指向目录的public_html

Both main domain and sub domain are pointing to directory "public_html"

我的.htaccess的根,它把所有的URL加www到www。 对于如如果用户输入example.com那么他将被重定向到www.example.com 如果用户输入 example.com/mypage.html 那么他将被重定向到 www.example.com/mypage.html

I have .htaccess on root which redirects any URL without www to www. For e.g. if user enters example.com then he will be redirected to www.example.com If user enters example.com/mypage.html then he will be redirected to www.example.com/mypage.html

现在的问题是,这也影响了我的子域。因为如果有人进入 something.example.com/visit.html 然后,他被重定向到 www.example.com/visit.html

Now the problem is this is also affecting my subdomain. Because if someone enters something.example.com/visit.html then he is redirect to www.example.com/visit.html

我不想要这个!如果用户输入的子域,然后我不想重定向到www域名。这是我在我的.htacces文件

I don't want this! If user enters subdomain then I don't want to redirected to www domain. This is what I have in my .htacces file

RewriteCond %{HTTP_HOST} !^www.stackoverflow.com$ [NC]
RewriteRule ^(.*)$ http://www.stackoverflow.com/$1 [R=301,L]

能否请你告诉我,我应该怎么做才能解决上述问题?

Can you please tell me what should I do to solve above problem?

感谢。

推荐答案

你可以访问你的Web服务器的配置?这是更好地配置Web服务器完成的。

Do you have access to your webserver configuration? This is better done by configuring the webserver.

在Apache将配置一个虚拟域这样的:

On apache you would configure one virtual domain like this:

<虚拟主机*:80>

        ServerName somedomainiwanttoredirect.com
        ServerAlias maybe.somemoredomainstoredirect.com
        ServerAlias orsubdomains.toredirect.com
        RewriteEngine On
        RewriteRule ^(.*)$ http://www.target.com/$1 [R=301,L]

< /虚拟主机>

和你的实际配置,www.target.com你添加子域,你不希望被重定向: ServerAlias​​ subdomain.target.com

and on your real configuration, the www.target.com you add your subdomains that you do not want to be redirected: ServerAlias subdomain.target.com

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

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