不带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>

相关阅读

正则表达式收集汇总

2020-12-1285

搜索: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-1087

4G降临,移动网站已经一发不可收拾,pc端和移动端官网并存。如何让别人访问你的pc端的官网直接跳转到移动端的网站呢?各位看官,小二上代码!来了!varurl=window.location.href;varurl_match=/vit=1$/i;if(!url.match(url_match)){if(navigator.userAgent.match(/(…

如何解决网站上传大文件的问题?

2020-10-10119

为了服务器的网络安全,避免因为超大文件导致服务器故障,所以对文件上传的大小限制是很有必要的,但是有些客户又有上传大文件的需求,比如上传pdf或者压缩包这种格式的文件,那么碰到这种情况下,如何解决这个问题呢?在浏览器输出phpinfo();查看LoadedConfigurationFile这个参数可以获取php.info的文件位置1:如果上传的文件太大,会导致…

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

2020-10-10221

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

为什么小程序的页面有二次跳转时会瞬间显示一下第一次的页面再跳转呢?

2020-10-10454

为什么小程序的页面有二次跳转时会瞬间显示一下第一次的页面再跳转呢?navigateToredirectToswitchTabtabBar先来看示例代码并且在微信开发者工具上测试下面看示例代码共有三个页面,分别是indexproductshowcartindex的js与wxmlPage({/*跳转到商品详情*/toProductshow:function(ev…

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

2020-10-10100

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…