#开启 rewrite
RewriteEngine on
<rule enabled="true" name="myRewriteRules">

指定程序目录:设置程序目录级重写的基准URL,所有的重定向都是基于这个URL,即平台根目录(IIS不支持该指令)。
RewriteBase /

#是否不是一个目录
RewriteCond %{REQUEST_FILENAME} !-d
<add input="{REQUEST_FILENAME}" negate="true" ignoreCase="false" matchType="IsDirectory" />

#是否不是一个文件
RewriteCond %{REQUEST_FILENAME} !-f
<add input="{REQUEST_FILENAME}" negate="true" ignoreCase="false" matchType="IsFile" />

[QSA,PT,L] QSA:保留参数GET|POST传值?a=1&b=2;PT:再把这个URL交给Apache处理;L:最后一个匹配项,不再往下匹配。
^(.*)$:匹配所有的路径映射到入口文件。关于[QSA,PT,L]在IIS中的同义,参考下面的《IIS 中几个常用的 Rewrite Rules 解释》

RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />

IIS 中几个常用的 Rewrite Rules 解释:

RewriteBase: 
IIS 的 Rewrite 规则中不支持 RewriteBase 设置,若通过IIS导入 .htaccess 文件会提示如下错误:

未转换此指令,因为它不受 IIS 支持: RewriteBase /。
His directive was not converted because it is not supported by IIS: RewriteBase /.

若注销或删除 RewriteBase 行,将导入成功。
The conversion process proceeds when the said line is commented out or removed.

如果需要把程序设置在某一个子目录,需要在IIS管理器中选择这个目录,操作如下:
IIS:Win+R - inetmgr.exe - IIS - 基本设置 - 物理路径(P): - D:\iis\subdir

----------------------------------

stopProcessing: 设置 true 时,不再往下匹配后续规则,默认为 false。原文如下:
A rule may have the StopProcessing flag turned on. When the rule action is performed (i.e. the rule matched) and this flag is turned on, it means that no more subsequent rules will be processed and the request will be passed to the IIS request pipeline. By default, this flag is turned off.

----------------------------------

appendQueryString: 设置 true 时,原始URL中的查询字符串将附加到替换的URL,默认为 true。原文如下:
Specifies whether the query string from the current URL is preserved during substitution. By default, if the value of the appendQueryString flag is not specified, it is assumed to be TRUE. This means that the query string from the original URL is appended to the substituted URL.

----------------------------------

ignoreCase: 设置 true 时,模式匹配不区分大小写,默认为 true。原文如下:
Use this attribute to control whether pattern matching for the condition should be case sensitive or case insensitive.

----------------------------------

logicalGrouping: logicalGrouping 是 <Conditions> 集合的一个属性,作用如下:
logicalGrouping="MatchAll" = 匹配所有条件;
logicalGrouping="MatchAny" = 仅匹配一个条件;

条件是在重写规则的<Conditions>集合中定义的。此集合有一个名为logicalGrouping的属性,用于控制条件的计算方式。如果规则具有条件,则仅当规则模式匹配且满足以下条件时,才会执行规则操作:

Conditions are defined within a <conditions> collection of a rewrite rule. This collection has an attribute called logicalGrouping that controls how conditions are evaluated. If a rule has conditions, then the rule action is performed only if rule pattern is matched and:

All conditions were evaluated as true, provided that logicalGrouping="MatchAll" was used.
At least one of the conditions was evaluated as true, provided that logicalGrouping="MatchAny" was used.

----------------------------------

Linux下 .htaccess 配置实例:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>

----------------------------------

IIS 下 web.config 配置实例:
<system.webServer>
    <rewrite>
        <rules>
            <rule name="myRewriteRules" stopProcessing="true" enabled="true">
            <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php?s=/{R:1}" appendQueryString="true" />
        </rule>
    </rules>
    </rewrite>
</system.webServer>

----------------------------------

The following links will help you find what you need.
https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module
https://social.msdn.microsoft.com/Forums/en-US/e043066b-1abd-42c4-8bf0-55398595db1f/help-converting-htaccess-to-webconfig?forum=iisurlrewritemodule
https://stackoverflow.com/questions/56647891/rewritebase-is-not-supported-in-iis
https://social.msdn.microsoft.com/Forums/en-US/4b383318-6f69-4f4c-b8f7-08309f843ba8/url-rewrite-error-when-importing-htaccess
https://stackoverflow.com/questions/44143767/htaccess-iis-mod-rewrite
https://social.msdn.microsoft.com/Forums/en-US/312adf1f-1cf8-4f07-9b19-54b591e105ba/iis7-wont-import-htaccess-file?forum=iisconfiguationandscripting
https://www.sitepoint.com/community/t/need-help-converting-htaccess-to-web-config/32092
https://processwire.com/talk/topic/8933-windows-iis/

重写规则(Rewrite Rules)在IIS和Linux服务器的配置区别相关推荐

  1. 在Linux服务器上配置phpMyAdmin--允许空密码

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  2. mysql在linux只有用空密码_在Linux服务器上配置phpMyAdmin--允许空密码

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  3. 在Linux服务器上配置phpMyAdmin

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  4. Linux服务器安全配置实例(二)用户账户权限配置

    没有绝对的安全 在上一篇文章<linux服务器安全配置实例(一)>中介绍了我对ssh服务的一些常用的安全配置和性能优化. 其实ssh服务是我们进入服务器的一扇大门,这扇大门是提供正常人使用 ...

  5. linux服务器相关配置查看

    linux服务器相关配置查看 1.查看GPU信息和使用情况 #Linux查看显卡信息: lspci是一个用来查看系统中所有PCI总线以及连接到该总线上的设备的工具. lspci | grep -i v ...

  6. 转:在Linux服务器上配置phpMyAdmin

    使用php和mysql开发网站的话,phpmyadmin是一个非常友好的mysql管理工具,并且免费开源,国内很多虚拟主机都自带这样的管理工具,配置很简单,接下来在linux服务器上配置phpmyad ...

  7. 实验室远程登录Linux服务器并配置环境

    实验室远程登录Linux服务器并配置环境 配置服务器环境的前提是已经登陆进入实验室服务器 如何登入服务器:手把手教你如何连上实验室的服务器_万事胜意-CSDN博客_实验室服务器 如何添加账户和设置密码 ...

  8. linux服务器基线配置

    linux服务器基线配置 账号 1 为不同用户创建不同账号: #useradd username #创建账号 #passwd username #设置密码 #chmod 750 directory # ...

  9. Linux服务器安全策略配置

    Linux服务器安全策略配置 1.口令长度限制 2.登录失败锁定 3.设置tty登录超时自动退出 4.ssh安全性配置 5.禁止USB外设 6.配置恶意软件防范策略 1.口令长度限制 设定用户默认密码 ...

  10. Linux服务器上配置Tomcat的docBase路径映射时遇到的坑

    场景 需求是将照片放置在Tomcat下的webapps目录下的img目录下. 这样能实现离线Tomcat迁移方便. Windows下的tomcat下的conf下的server.xml中的路径映射配置为 ...

最新文章

  1. tomcat 部署站点时遇到的部分问题以及解决方案
  2. 吴敏霞(为奥运冠军名字作诗)
  3. win 2008 控制共享文件夹大小_win10如何一键网络共享
  4. 创建交互式shell脚本对话框
  5. java RSA加密解密--转载
  6. 使用HttpClient MultipartEntityBuilder 上传文件,并解决中文文件名乱码问题
  7. 前端脚本API发布 | Java 开源企业信息化建设平台O2OA平台
  8. 基于Java开发的Java毕业设计实战项目
  9. 星期一到星期日的英文_缩写_读音_巧记方法
  10. 开口式霍尔电流传感器AHKC在直流配电改造的应用
  11. 【周赛-简单】5495. 圆形赛道上经过次数最多的扇区
  12. TCP/IP协议 - 三次握手四次挥手(入门易懂版)
  13. TCP报文格式及三次握手详解
  14. Python 3如何安装OpenCV
  15. 3万字智慧工业园区整体解决方案
  16. python day003_int/str/bool/for循环
  17. 新概念第一册听力笔记
  18. vray 用于室内渲染的10大技巧,看进来!
  19. Android开发之语音识别,Android开发知识体系
  20. centos 7 中文输入法的安装和启用

热门文章

  1. 【最优方案】合唱队形
  2. python进行邮件文件.eml.pst.msg信息提取(包括附件)
  3. 九阴服务器延迟高怎么解决,6月24日部分互通升级服务器延迟开服公告
  4. 触摸屏 触摸操作 鼠标点击事件
  5. 三大方面解析虚拟化技术在云计算数据中心中的应用
  6. 全球四大国际反垃圾邮件组织介绍
  7. Android Browser默认主页网址(验证于KK,L,M,N,O)
  8. 慎用windows EFS文件加密
  9. 我去补了个牙,然后发现,未知的恐惧让人很绝望
  10. python乘积函数_Python中的乘法函数