【发布时间】:2021-07-31 03:01:44
【问题描述】:
我需要:
-
添加 www,因此用户将:
- 输入
https://example.com/test.html - 在浏览器中查看
https://www.example.com/test.html - 从
example.com/test.html获取文件
- 输入
-
添加 http -> https 重定向,因此用户将:
- 输入
http://www.example.com/test.html - 在浏览器中查看
https://www.example.com/test.html - 从
example.com/test.html获取文件
- 输入
-
添加子域 silent 重定向,因此用户将:
- 输入
https://new.example.com/test.html - 在浏览器中查看
https://new.example.com/test.html - 从
example.com/new/test.html获取文件
- 输入
-
当然还有结合,例如:
- 输入
http://new.example.com/test.html - 在浏览器中查看
https://new.example.com/test.html - 从
example.com/new/test.html获取文件
- 输入
这是否可以通过 .htaccess 文件实现,最终如何实现?
www 和 https 转发对我来说已经可以正常工作了,但我不知道如何对子域进行静默转发:
RewriteEngine On
# https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# WWW
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^new\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
谢谢。
【问题讨论】:
-
请在您的问题中分享您的 htaccess 规则文件,这是鼓励提问者在他们的问题中投入的努力,谢谢。
-
我已经尝试了一些东西,但是我现在在 .htacces 文件中没有任何东西,因为我尝试的所有东西都不起作用。
-
就像努力尝试添加您尝试过的任何内容一样,没有对错,否则问题可能会出现在题外话类别中,谢谢。一旦我添加它,我会尽力在这里提供帮助,干杯。
-
谢谢,我添加了 www 和 https 的规则,这对我来说很好,但我不知道如何添加静默转发。
-
new.example.com和example.com是否指向同一主机上的同一目录?