.htaccess 从子域重定向到域

发布于 2024-09-29 05:01:44 字数 392 浏览 1 评论 0原文

我在这里尝试了一堆示例并对其进行了修改,但没有一个完全符合我的需要,因此要么因 500 服务器错误而失败(意味着重写规则错误),要么仅将子域重定向到域而不是任何页面的完整 URL。

我需要将 blog.mydomain.com 下的所有 URL 重定向到 www.mydomain.com/blog, 即重定向 blog.mydomain.com/page1 到 www.mydomain.com/blog/page1

RedirectMatch 301 ^/ http://mydomain.com/blog/

会将 blog.mydomain.com 的所有 URL 重定向到 mydomain.com/blog/ 的根目录,而不是完整的 URL。有什么想法吗?

I've tried a bunch of examples here on SO and modifed them, but none are exactly what I need and as a result either fail with 500 server errors (meaning the rewrite rules are wrong) or redirect just the subdomain to the domain and not any of the full URLs of pages.

I need to redirect all URLs under blog.mydomain.com to www.mydomain.com/blog,
i.e. redirect blog.mydomain.com/page1 to www.mydomain.com/blog/page1

This

RedirectMatch 301 ^/ http://mydomain.com/blog/

redirects all URLs of blog.mydomain.com to the root of mydomain.com/blog/, not the full URL. Any ideas?

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

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

发布评论

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

评论(2

丿*梦醉红颜 2024-10-06 05:01:44
RedirectMatch permanent (.*) http://mydomain.com/blog/$1
RedirectMatch permanent (.*) http://mydomain.com/blog/$1
谁的新欢旧爱 2024-10-06 05:01:44

我用它来将一个域重定向到另一个域,但对于子域/子目录应该可以正常工作:

RewriteCond %{HTTP_HOST} ^blog\.mysite\.com$ [NC]
RewriteRule ^ http://mysite.com/blog%{REQUEST_URI} [R=301,L]

I use this to redirect one domain to another, but should work fine for subdomains/subdirectories:

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