子域及其文件夹重写

Subdomain and it's folder rewrite

让我们解释一下我的问题。我有一个包含子域文件的文件夹。

包含子域文件的文件夹称为“子域”。

我的域名是 example.com.

我的子域名是 sub.example.com.

问题是,当我键入 https://sub.example.com 时,它可以工作,但当我键入 https://example.com/subdomainhttps://sub.example.com/subdomain

时,会加载相同的内容

我的问题是,如何实现 https://example.com/subdomain(.*) 将重定向到 https://sub.example.com(.*) 以及如何实现 https://sub.example.com/subdomain(.*) 将重定向到 https://sub.example.com(.*)

当前.htaccess配置如下:

RewriteCond %{HTTP_HOST} ^sub\.example\.com$
RewriteRule (.*) /subdomain/%1%{REQUEST_URI} [L]

您可以将此重定向规则用作站点根目录 .htaccess 或 subdomain/.htaccess:

中的 topmost 规则
RewriteEngine On

# use THE_REQUEST to detect presence of /subdomain/ in original URL
RewriteCond %{THE_REQUEST} \s/+subdomain/(\S*) [NC]
RewriteRule ^ https://sub.example.com/%1 [L,NE,R=301]

THE_REQUEST 变量表示 Apache 从您的浏览器收到的原始请求,并且在执行其他重写指令后不会被覆盖。此变量的示例值为 GET /index.php?id=123 HTTP/1.1