.htaccess子域重定向问题

发布于 2024-10-09 07:34:51 字数 685 浏览 0 评论 0原文

我有一个网站 www.example.com 并且有一个子域 something.example.com

主域和子域都指向

我的 目录“public_html”根目录上的 .htaccess 将任何不带 www 的 URL 重定向到 www。 例如,如果用户输入 example.com 那么他将被重定向到 www.example.com 如果用户输入 example.com/mypage.html 那么他将被重定向到 www.example.com/mypage.html

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

我不想要这个!如果用户输入子域,那么我不想重定向到 www 域。这是我的 .htacces 文件中的内容,

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

您能告诉我应该做什么来解决上述问题吗?

谢谢。

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

Both main domain and sub domain are pointing to directory "public_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

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

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?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫竹語嫣☆ 2024-10-16 07:34:51

您有权访问您的网络服务器配置吗?最好通过配置网络服务器来完成此操作。

在 apache 上,您可以像这样配置一个虚拟域:

        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添加您不希望重定向的子域:
<代码>
服务器别名 subdomain.target.com

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

On apache you would configure one virtual domain like this:

<VirtualHost *:80>

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

</VirtualHost>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文