沐沐 发表于 2020-6-30 10:10:41

Asp/Aspx程序如何设置伪静态/重定向等功能

说明:
    Asp/Aspx程序一般都有默认的一套配置文件,所以面板暂不支持自动配置伪静态功能,需要自己手动配置。
    web.config路径在网站(站点)根目录下

如何手动配置?

分为两种情况,情况如下:

1、当Asp程序根目录不存在web.config文件,或者配置文件内容为如下代码时:

可以直接将面板生成的代码复制到伪静态,保存即可<?xml version="1.0" ?>
<configuration>
    <location allowOverride="false" inheritInChildApplications="false" path=".">
      <system.webServer>
            <rewrite>
                <rules configSource="web_config\rewrite.config"></rules>
            </rewrite>
            <defaultDocument configSource="web_config\default.config"></defaultDocument>
            <httpErrors configSource="web_config\httpErrors.config"></httpErrors>
            <handlers configSource="web_config\php.config"></handlers>
      </system.webServer>
    </location>
</configuration>
      

2、当Aspx程序和Asp程序根目录自带了web.config文件时:
   如原配置为以下格式:
   

3、(重要)当Asp网站不存在原有配置文件时,将网站目录下的web.config文件内容替换成以下代码即可<?xml version="1.0" ?>
<configuration>
      <location path="." allowOverride="false" inheritInChildApplications="false">
          <system.webServer>
               <rewrite>
                     <rules>                        
                         <rule name="http_toHttps" stopProcessing="true">
                           <match url="(.*)"/>
                           <conditions>
                                  <add input="{HTTPS}" pattern="off" ignoreCase="true"/>
                           </conditions>
                           <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}"/>
                           </rule>
                     </rules>
                </rewrite>
          </system.webServer>
      </location>
</configuration>



   手动修改后的代码:

   注意1:如果【图1】中存在<system.webServer>/<rewrite>/<rules>,则直接加入在下级节点
   注意2:如果【图1】中不存在<system.webServer>/<rewrite>/<rules>,则需要手动添加,下图为手动添加【<system.webServer>/<rewrite>/<rules>】
   







Warren 发表于 2021-3-31 00:56:39

经过测试,把文件内的代码替换为以下代码是可以的
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
      <rewrite>
            <rules>
                <rule name="HTTP to HTTPS redirect" stopProcessing="true">
                  <match url="(.*)" ></match>
                  <conditions>
                        <add input="{HTTPS}" pattern="^OFF$" ></add>
                  </conditions>
                  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" ></action>
                </rule>
            </rules>
      </rewrite>
    </system.webServer>
</configuration>

mrwu888 发表于 2020-6-30 11:13:48

:)学习下

WP建站 发表于 2020-6-30 16:06:11

这个感觉确实比较麻烦,我前两天也遇到案例,一个客户说安装环境既要支持asp,也要php,头疼,用win系统的织梦开启伪静态也麻烦的很。。

痞子哥 发表于 2020-7-1 11:19:30

多谢楼主分享!

yafan99 发表于 2020-11-8 10:22:58

做了301跳转www后再301跳转https,浏览器均打不来网站,提示跳转太多:'(

q292823885 发表于 2020-11-11 13:23:55

加在下级了 无法跳转

kunhai 发表于 2020-11-20 21:09:38

<system .webserver>
<rewrite>
   <rules>
   <rule name="http_toHttps" stopProcessing="true">
        <match url="(.*)"/>
        <conditions>
                <add ignoreCase="true" input="{HTTPS}" pattern="off"/>
        </conditions>
        <action redirectType="Permanent" type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
</system .webserver>

kunhai 发表于 2020-11-20 21:10:18

我配置了好像不得行,不能强制开启

宝塔用户_ofqmeh 发表于 2020-11-21 20:38:01

不行呀。这咋搞

宝塔用户_ishigv 发表于 2021-9-18 13:17:30

Warren 发表于 2021-3-31 00:56
经过测试,把文件内的代码替换为以下代码是可以的

IIS管理器内该网站的 SSL设置,“要求SSL”一定不要勾选,会造成 http 403 或者 500 错误,无法跳转 https。

宝塔用户_hyyyrb 发表于 2023-2-1 15:38:49

iis 7.5的绑定SSL 网站都打不开了,不知道为什么?
页: [1]
查看完整版本: Asp/Aspx程序如何设置伪静态/重定向等功能