不带www跳转到www,http跳转到https

栏目:建站技术 2023-03-23

一:windows操作系统,在网站根目录下,新建web.config这个文件
1:不带www跳转到www代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="to www" stopProcessing="true">
          <match url=".*" />
          <conditions>
              <add input="{HTTP_HOST}" pattern="^sznest\.net$" />
          </conditions>
          <action type="Redirect" url="http://www.sznest.net/{R:0}" />
        </rule>
        <rule name="http to https" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

2:http跳转到https代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="http to https" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

也可以用下面的
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="http to https" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" ></match>
          <conditions logicalGrouping="MatchAll">                       
            <add input="{HTTP_FROM_HTTPS}" pattern="^on$" negate="true" ></add>  
          </conditions>
          <action type="Redirect" url="https://www.顶级域名/{R:1}" redirectType="Permanent" ></action>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

3:不带www跳转到www,http跳转到https代码示例
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="to www" stopProcessing="true">
          <match url=".*" />
          <conditions>
              <add input="{HTTP_HOST}" pattern="^sznest\.net$" />
          </conditions>
          <action type="Redirect" url="http://www.sznest.net/{R:0}" />
        </rule>
        <rule name="http to https" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

二:Linux操作系统,在网站根目录下,新建.htaccess这个文件
1:不带www跳转到www代码示例
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^sznest.net [NC]
    RewriteRule ^(.*)$ http://www.sznest.net/$1 [L,R=301]
</IfModule>

2:http跳转到https代码示例
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>

3:不带www跳转到www,http跳转到https代码示例
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^sznest.net [NC]
    RewriteRule ^(.*)$ http://www.sznest.net/$1 [L,R=301]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ http://www.sznest.net/$1 [L,R=301]
</IfModule>

相关阅读

用火狐打开百度一直加载s1.bdstatic.com的解决办法

2020-10-10736

一直用火狐浏览器,火狐浏览器插件多,很合适网页开发人员使用,以前一直用的好好的,但是今天使用的时候突然发现没有以前好用了,打开百度的官网一直很卡,通过FIREBGU发现在打开百度官网的时候一直会加载s1.bdstatic.com这个网站,无语,怎么打开百度的官网还需要链接s1.bdstatic.com这个网站这个网站吗?难道是百度被黑了,或者是自己的浏览器被…

正则表达式收集汇总

2020-12-12100

搜索:empty(($)tr[&#39;([a-z]{1,})&#39;]),可以查找这样的empty($tr[&#39;digest&#39;]),然后可以替换成!$digest替换:!$1$2匹配A标签的超连接的正则表式如下$pattern=&quot;/&lt;a[^&gt;]+?href=[&quot;&#39;]?([^&quot;&#39;]+)…

小程序的下单与支付的业务流程

2020-10-10243

1:小程序携带商品信息调用第三方服务器的下单API2:第三方服务器下单API对小程序带来的商品作库存量检测3:如果检测通过,第三方服务器就会保存这个订单并且告之小程序下单成功4:小程序调用第三方服务器的支付api5:第三方服务器API调用微信的预订单API[WxPayApi::unifiedOrder](注意第三方服务器是无法完成支付的,这个订单实际是在微信…

小程序倒计时wxml与js

2020-10-1085

小程序倒计时jsPage({data:{windowHeight:654,maxtime:&quot;&quot;,isHiddenLoading:true,isHiddenToast:true,dataList:{},countDownDay:0,countDownHour:0,countDownMinute:0,countDownSecond:0,},/…

小程序列表多个批量倒计时

2020-10-10120

Page({onShow(){letthat=this;vardates={datetime:[{dat:0,name:&#39;zs&#39;},{dat:6,name:&#39;ls&#39;},{dat:10,name:&#39;ww&#39;}]}//console.log(dates)//数据letlen=dates.datetime.length…

如何解决QQ显示未启用的问题

2024-08-8285

没设置临时会话,一般都会出现下面的状况。QQ放在网站上作为客服,必须设置临时会话。或者点击之后,要求加为好友才可以对话。解决这个问题的步骤如下:一、登陆腾讯官方网站:http://wp.qq.com/二、登陆之后,点“设置”,按下图所示,全部打勾。这个必须设置,不设置,不能临时会话,就会显示“未启用”。这一步是关键,必须设置。(1)先看服务有没被停用:如停用…