Php 需要子域URL的htaccess重定向代码解决方案以重定向到不带www的URL
我有一个domain example.com,我在.htaccess文件中添加了以下重定向代码以重定向到,并且 1) 当我在浏览器example.com中加载URL时,它会重定向到 2) 我在example.com中创建了一个子域文件夹“test”。因此,当我加载URL example.com/test时,它被重定向到 需要解决以下问题: 1) 当我加载URL test.example.com时,它被重定向到,但我希望它被重定向到 2) 当我加载URL www.example.com/test时,它被重定向到,但我希望它被重定向到 3) 当我加载URL www.example.com时,它被重定向到,但我希望它被重定向到 有人能帮忙吗?提前感谢您可以使用此规则Php 需要子域URL的htaccess重定向代码解决方案以重定向到不带www的URL,php,apache,.htaccess,redirect,mod-rewrite,Php,Apache,.htaccess,Redirect,Mod Rewrite,我有一个domain example.com,我在.htaccess文件中添加了以下重定向代码以重定向到,并且 1) 当我在浏览器example.com中加载URL时,它会重定向到 2) 我在example.com中创建了一个子域文件夹“test”。因此,当我加载URL example.com/test时,它被重定向到 需要解决以下问题: 1) 当我加载URL test.example.com时,它被重定向到,但我希望它被重定向到 2) 当我加载URL www.example.com/test时
RewriteEngine on
#redirect subdomain to https
RewriteCond %{HTTPS}#%{HTTP_HOST} ^off#(sub\.domain\.com)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
#redirect main domain to https www
RewriteCond %{HTTPS}#%{HTTP_HOST} ^off#(?:www\.)?(example\.com)$
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R]
在测试这些新重定向之前,请清除浏览器缓存
如果您有多个子域,可以使用以下模式将它们重定向到https:
^off#(sub\.domain\.com|sub2.example.com|sub3.example.com|other)$
你可以使用这个规则
RewriteEngine on
#redirect subdomain to https
RewriteCond %{HTTPS}#%{HTTP_HOST} ^off#(sub\.domain\.com)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
#redirect main domain to https www
RewriteCond %{HTTPS}#%{HTTP_HOST} ^off#(?:www\.)?(example\.com)$
RewriteRule ^ https://www.%1%{REQUEST_URI} [NE,L,R]
在测试这些新重定向之前,请清除浏览器缓存
如果您有多个子域,可以使用以下模式将它们重定向到https:
^off#(sub\.domain\.com|sub2.example.com|sub3.example.com|other)$
您需要提供有关您的需求的更多详细信息。如果您尝试加载
www.example.com
,当前会发生什么情况?我现在已经更新了问题对不起,现在我已经清楚地更新了问题。它重定向到https://www.www.example.com/您需要提供有关您的要求的更多详细信息。如果您尝试加载www.example.com
,当前会发生什么情况?我现在已经更新了问题对不起,现在我已经清楚地更新了问题它重定向到https://www.www.example.com/