繁体   English   中英

将 .htaccess 转换为 web.config

[英]Convert .htaccess to web.config

我正在使用 IIS-7 并正在从基于 linux 和 apache 的服务器环境中移动站点。 我知道 web.config 与 .htaccess 做同样的工作。 我希望将以下行从我的 .htaccess 文件转换为 web.config 文件。 我从哪里开始?

Options +FollowSymlinks
RewriteEngine On
RewriteRule ([A-Za-z0-9/_-]+).(jp(e?)g|gif|png)$ thumb.php?src=../../uploads/default/files/$1.$2&size=160x90

要将规则从.htaccess转换为web.config,您可以使用IIS URL重写模块的导入功能:

  1. 转到IIS管理器
  2. 单击树中的站点
  3. 双击功能视图中的URL重写
  4. 单击动作”面板中的“ 导入规则”
  5. 将.htaccess规则粘贴到重写规则文本框中,您将在下面看到转换后的规则。

有关此功能的更多信息

例如,您的规则将转换为以下规则:

<rewrite>
  <rules>
    <rule name="Imported Rule 1">
      <match url="([A-Za-z0-9/_-]+).(jp(e?)g|gif|png)$" ignoreCase="false" />
      <action type="Rewrite" url="thumb.php?src=../../uploads/default/files/{R:1}.{R:2}&amp;size=160x90" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

只需在记事本上创建 web.config 文件或编辑根文件夹中的文件并复制并粘贴:

<?xml version="1.0" encoding="UTF-8"?> 
  <configuration> 
  <system.webServer> 
    <rewrite> 
      <rules> 
        <rule name="Remove index.php rule" stopProcessing="true"> 
          <match url=".*" ignoreCase="false"/> 
          <conditions> 
            <add input="{URL}" pattern="^/(media|skin|js)/" ignoreCase="false" negate="true" /> 
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
          </conditions> 
          <action type="Rewrite" url="index.php" /> 
        </rule> 
      </rules> 
    </rewrite> 
  </system.webServer> 
</configuration>

参考: https://gist.github.com/sabbour/e49b3ac9e1438c93d5fb

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM