.htaccess 子域重定向

发布于 2024-12-24 01:08:16 字数 988 浏览 4 评论 0 原文

我的服务器以某种方式配置为接受任何字符串作为现有的子域名。该子域不会重定向,而是显示内容。例如:

bla.example.com // 显示http://example.com

的内容

blabla.example.com // 显示http://example.com < strong>lorem.example.com/events/ // 显示http://example.com/events

所以你可以使用“stackoverflow.example.com”并且它会起作用。

我想创建一个 .htaccess 规则来覆盖此行为。我想将 http://*.example.com/* 重定向到 http://www.example.com/*

到目前为止我所做的一切都是将 http://example.com 重定向到 http://www.example.com (这是另一种行为我想保留)

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

谢谢你的帮助!

My server is somehow configured to accept any string as a existing subdomian. This subdomains doesn't redirect, they show content instead. For example:

bla.example.com // shows the content of http://example.com

blabla.example.com // show the content of http://example.com

lorem.example.com/events/ // shows the content of http://example.com/events

So you can use "stackoverflow.example.com" and it will work.

I want to create an .htaccess rule to overwrite this behavior. I want to redirect http://*.example.com/* to http://www.example.com/*

Everything I have done so far is redirect http://example.com to http://www.example.com (wich is another behavior I want to keep)

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

Thank you for your help!

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

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

发布评论

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

评论(1

残疾 2024-12-31 01:08:16

尝试将以下内容添加到域根文件夹中的 htaccess 文件中

RewriteEngine on
RewriteBase /

#if its not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#redirect it to www.example.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]

Try adding the following to your htaccess file in the root folder of your domain

RewriteEngine on
RewriteBase /

#if its not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#redirect it to www.example.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文