问题描述
第一种情况:
我尝试将http重定向到https,并且遵循以下规则行之有效.
I tried to redirect http to https and following rule works well.
例如: http://subdomain.domain.com 到 https://subdomain.domain.com .
For example: http://subdomain.domain.com to https://subdomain.domain.com.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
第二种情况:我试图将 http://subdomain.domain.com 重定向到 http://subdomain.domain/folder .为此,我使用了以下规则:
Second Case:I tried to redirect http://subdomain.domain.com to http://subdomain.domain/folder. For this I used this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com
RewriteRule ^(.*)$ /folder/$1
我想要这些重定向:
http://subdomain.domain.com 到 https://subdomain.domain.com/folder
http://subdomain.domain.com to https://subdomain.domain.com/folder
和
https://subdomain.domain.com 到 https://subdomain.domain.com/folder
https://subdomain.domain.com to https://subdomain.domain.com/folder
我尝试合并以上规则,但是没有运气.
I tried merging the above rules but no luck.
还有一件事,我没有使用.htaccess
,而是将这些规则/etc/apache2/sites-available/default
.
One more thing, I am not using .htaccess
,instead I put these rules to/etc/apache2/sites-available/default
.
推荐答案
回答我自己的问题.
实际上/etc/apache2/sites-available/
- 默认
- default-ssl
我放置了将http
重定向为https
的规则,
I put the rule to redirect http
to https
as
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
在default
文件和
放置规则以将其重定向到子域的folder
put rule to redirect to sub-domain's folder
as
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com
RewriteRule ^(.*)$ /folder/$1
在default-ssl
文件中.
这篇关于将http重定向到https,然后将其重定向到子域的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!