在配置.htaccess文件重定向HTTP子域到HTTPS等效咨询 [英] Advice on Configuring .HTaccess file to Redirect HTTP Subdomain to HTTPS Equivalent

查看:96
本文介绍了在配置.htaccess文件重定向HTTP子域到HTTPS等效咨询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定有一个简单的回答这个问题,但我已经冲刷穿过可用线程和它要么不存在或者我太无知承认它开始在我的脸上。 <一href="http://stackoverflow.com/questions/1545097/redirect-subdomain-request-to-subdirectory-https-using-htaccess">This似乎是答案,但我就是不能正确配置。

问题:我如何设置的.htaccess使所有子域名转发到自己的HTTPS等效,同时也允许在主域本身得到移植到HTTPS的相同呢?换句话说:

  
      
  1. hxxp://subdomain1.domain.com - > hxxps://subdomain1.domain.com
  2.   
  3. hxxp://subdomain2.domain.com - > hxxps://subdomain2.domain.com
  4.   
     

...等,但也...

     
      
  1. hxxp://domain.com - > hxxps://domain.com
  2.   

当前配置: 我的.htaccess设置为提供无条件转发如下:

  RewriteEngine叙述上
的RewriteCond%{} SERVER_PORT 80
重写规则^(。*)$ https://domain.com/$1 [R,L]
 

要达到我想要的,我认为必须有一些方法来定义一个通配符,并通过通配符的子域的结果 - 无论是,subdomain1,subdomain2或没有值 - 实际的重定向。

任何帮助将是非常美联社preciated。

解决方案

我没有测试过这一点,但它应该让你捕捉的子域以及请求。

  RewriteEngine叙述上
的RewriteCond%{} SERVER_PORT 80
的RewriteCond%{HTTP_HOST} ^(。*)\。YOURDOMAIN \ .COM $
重写规则^ $ HTTPS(*)://%1.domain.com/$1 [R,L]
 

这条规则但是,不会为不包含子目录的要求工作,所以你实际上需要两个规则。

 的RewriteCond%{} SERVER_PORT 80
的RewriteCond%{HTTP_HOST} ^ YOURDOMAIN \ .COM $
重写规则^(。*)$ https://domain.com/$1 [R,L]
 

I'm sure there is an easy answer to this question, but I've scoured through through available threads and its either not there or I'm too ignorant to recognize it starting in my face. This seems to be the answer, but I just can't configure correctly.

Question: How do I set up .htaccess so that all subdomains are forwarded to their https equivalents, while also allowing the main domain itself get ported to its https equivalent? In other words:

  1. hxxp://subdomain1.domain.com --> hxxps://subdomain1.domain.com
  2. hxxp://subdomain2.domain.com --> hxxps://subdomain2.domain.com

...and so on, but also...

  1. hxxp://domain.com --> hxxps://domain.com

Current Configuration: My .htaccess is set up to provide an unconditional forward as follows:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

To achieve what I want, I would think that there must be some way to define a wildcard and pass the result of that wildcard as the subdomain - whether, subdomain1, subdomain2 or a value of nothing - to the actual redirect.

Any help would be much appreciated.

解决方案

I haven't tested this, but it should allow you to capture the subdomain as well as the request.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.*)\.yourdomain\.com$
RewriteRule ^(.*)$ https://%1.domain.com/$1 [R,L]

This rule however, will not work for requests that do not contain a subdirectory, so you actually need two rules.

RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

这篇关于在配置.htaccess文件重定向HTTP子域到HTTPS等效咨询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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