不带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="https://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 ^(.*)$ https://www.sznest.net/$1 [L,R=301]
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.sznest.net/$1 [L,R=301]
</IfModule>

相关阅读

帝国CMS-采集关键的经验总结

2020-10-1025

采集关键的几个步骤一:先建好栏目二:增加采集节点(需要选择栏目)三:录入节点名称四:如果有很多页,只需录入采集页面地址方式二中的内容地址为https://www.sznest.net/news.asp?big_class_id=3&amp;page=[page]页码从1到多少页之间、间隔倍数为1(这个多少页即被采集的网站的实际页数,注意这里修改后,在采集页面…

asp用正则批量替换过滤表中所有行的内容中的图片

2020-10-1023

SetHF=NewRegExp&#39;建立正则表达式。HF.Pattern=&quot;《img[^&gt;]*&gt;&quot;&#39;设置模式、《请替换成英文的左尖括号。HF.IgnoreCase=True&#39;设置是否区分字符大小写。HF.Global=True&#39;设置全局可用性。Setconn=Server.CreateObject(…

AJAX随机调用数组中不重复的元素

2020-10-1021

读以记事本中的网址,记事本里中有多个网址,每个一行,然后使用AJAX循环请求随机出来的部分不重复的网址setsrmObj=server.CreateObject(&quot;adodb.stream&quot;)srmObj.type=1srmObj.mode=3srmObj.opensrmObj.Position=0srmObj.LoadFromFile(…

如何让你的PHP网站变得更安全

2020-10-1060

安全配置一(1)打开php的安全模式php的安全模式是个非常重要的内嵌的安全机制,能够控制一些php中的函数,比如system(),同时把很多文件操作函数进行了权限控制,也不允许对某些关键文件的文件,比如/etc/passwd,但是默认的php.ini是没有打开安全模式的,我们把它打开:safe_mode=on(2)用户组安全当safe_mode打开时,sa…

DOS命令批量获取文件夹内的名称及批量修改文件夹内名称

2020-10-10174

批量提取文件夹内文件名一:在文件夹内新建一个文本文件,名称随便起,这里为了演示,暂时起名叫!!!.TXT,放入下面的内容,!!!!!!.TXT这个是被生成的文件,用于存放文件夹内所有的文件名用的DIR*.*/B&gt;!!!!!!.TXT二:将!!!.TXT文件名的后缀改成.bat,然后双击运行,生成了!!!!!!.TXT文件三:打开!!!!!!.TXT文件…

FTP上的文件不宜在线编辑

2022-04-4606

知道FTP软件使用的都知道,打开软件登录某一空间后,一边是本地的文件,另一边是服务器上的文件,而FTP软件就是连接本地与虚拟主机的桥梁,因为有了该软件,线上线下的上传下载就显得非常的简单。一般情况下,如果要对服务器上的文件进行修改,可以先将其下载到本地,再用dr将其打开进行编辑,待编辑到满意后,再上传上去,覆盖以前的文件,或是将以前的文件改个名字,直接上传上…