htaccess:如果通过子域访问,如何将文件夹中的所有文件重定向到非子域?

发布于 2024-10-01 09:37:57 字数 345 浏览 0 评论 0原文

使用 htaccess,如果在 /folder/myfiles/ 中访问文件,我需要删除 url 的子域部分,

例如。我需要重定向 sub.domain.com/folder/myfiles/anyfile.php 到 domain.com/folder/myfiles/anyfile.php

在 /folder/myfiles/ 中找到的任何文件如果通过子域访问,则必须重定向到根域上的同一文件。

背景:该网站在多站点上使用 WordPress 博客的子域。有一个第三方应用程序安装到根域上的文件夹中,许可证仅对根域有效,尝试通过子域访问它会使许可证无效,因此我需要确保该文件夹中的任何文件都必须是通过根域而不是子域访问。

using htaccess, I need to remove the subdomain part of the url if a file is accessed in /folder/myfiles/

eg. I need to redirect
sub.domain.com/folder/myfiles/anyfile.php
to
domain.com/folder/myfiles/anyfile.php

any file found in /folder/myfiles/ if accessed via a subdomain must be redirected to the same file on the root domain.

background: the site uses subdomains for wordpress blogs on multisite. There is a 3rd party app installed to a folder on the root domain, the licence is only valid for the root domain and attempting to access it via a subdomain invalidates the licence so I need to make sure that any file in that folder must only be accessed via the root domain and not a subdomain.

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

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

发布评论

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

评论(1

Oo萌小芽oO 2024-10-08 09:37:57

在文件夹的 .htaccess 中:

RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule (.*) http://domain.com/folder/myfiles/$1

在根 .htaccess 或服务器配置中:

RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule ^/?(folder/myfiles(/.*)?)$ http://domain.com/$1

In the folder's .htaccess:

RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule (.*) http://domain.com/folder/myfiles/$1

In the root .htaccess or server config:

RewriteCond %{HTTP_HOST} sub.domain.com
RewriteRule ^/?(folder/myfiles(/.*)?)$ http://domain.com/$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文