将http重定向到https,然后将其重定向到子域的文件夹? [英] Redirect http to https and then redirect it to subdomain's folder?

查看:77
本文介绍了将http重定向到https,然后将其重定向到子域的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一种情况:

我尝试将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/

  1. 默认
  2. 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,然后将其重定向到子域的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆