如何将htaccess转换为web.config

时间:2016-01-31 08:24:35

标签: php apache .htaccess mod-rewrite web-config

我正在开展一个网站项目,我必须在客户端的服务器上安装该网站。他有一个Godaddy Windows帐户,它不接受.htaccess文件,而是使用web.config。我真的不知道怎么写web.config,我也快点。我试图用一些在线转换器转换我的htaccess,但当然它也不起作用。你能帮帮我吗?

我的htaccess:

Options -Multiviews
RewriteEngine On

# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME] !-d
RewriteCond %{REQUEST_FILENAME] !-f

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

生成器从web.config生成的内容:

<rule name="rule 1w" stopProcessing="true">
    <match url="^"  />
    <action type="Rewrite" url="/-"  />
</rule>
<rule name="rule 2w" stopProcessing="true">
    <match url="^(.+)$"  />
    <action type="Rewrite" url="/index.php?url={R:1}" appendQueryString="true"/>
</rule>

1 个答案:

答案 0 :(得分:0)

Aaand我在发布此问题后的2分钟内修复了它!

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Imported Rule 1" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="/index.php?url={R:1}"  appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>