简体   繁体   English

将 .htaccess 转换为 web.config

[英]Convert .htaccess to web.config

I'm using IIS-7 and am moving a site over from a linux and apache based server environment.我正在使用 IIS-7 并正在从基于 linux 和 apache 的服务器环境中移动站点。 I know web.config does the same job as .htaccess.我知道 web.config 与 .htaccess 做同样的工作。 I'm looking to convert the following lines from my .htaccess file to a web.config file.我希望将以下行从我的 .htaccess 文件转换为 web.config 文件。 Where would I begin?我从哪里开始?

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

To convert rules from .htaccess to web.config you can use import feature of the IIS URL Rewrite Module : 要将规则从.htaccess转换为web.config,您可以使用IIS URL重写模块的导入功能:

  1. go to IIS Manager 转到IIS管理器
  2. click you site in the tree 单击树中的站点
  3. double-click URL Rewrite in the Feature View 双击功能视图中的URL重写
  4. click Import Rules in the Actions panel 单击动作”面板中的“ 导入规则”
  5. paste your .htaccess rules into the Rewrite rules textbox and you'd see your converted rules below. 将.htaccess规则粘贴到重写规则文本框中,您将在下面看到转换后的规则。

More info about this feature. 有关此功能的更多信息

For instance your rules are converted into these ones: 例如,您的规则将转换为以下规则:

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

Just create a web.config file on Notepad or edit the one you have on the root folder and copy and paste this:只需在记事本上创建 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>

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

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

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