bakingsoda
bakingsoda

Reputation: 57

Routing web.config to index.php within folder

I have no experience working with windows web servers so i'm a bit lost. I'd like to setup a folder that routes all urls to index.php. I have attempted a few different configurations without any of them working.

How I would do it in .htaccess:

RewriteEngine on
RewriteBase /Software
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /folder/index.php?/$1 [NC,QSA,L]

My attempts with web.config:

<configuration> 
  <system.webServer>
      <rewrite>
          <rules>
              <rule name="Redirect To Index" stopProcessing="true">
                  <match url=".*" />
                  <conditions>
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                  </conditions>
                  <action type="Rewrite" url="/folder/index.php" />
              </rule>
          </rules>
      </rewrite>
  </system.webServer>
</configuration>

Upvotes: 0

Views: 1900

Answers (1)

Abraham Qian
Abraham Qian

Reputation: 7522

Place the below rules in webconfig file under the Software directory. If the webconfig file doesn't exists, create it. the rules in it can be recognized by IIS.

<configuration> 
  <system.webServer>
<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" />
      <conditions>
        <add input="{R:1}" pattern="^(index\.php|images|robots\.txt)" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="/folder/index.php?/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>
  </system.webServer>
</configuration>

IIS rewrite rules are designed with a different philosophy. It doesn’t support the RewriteBase command. We just place the webconfig file in the corresponding folder. The rest URL rules will work in the specific directory.
In addition, the rest URL rules could be automatically converted into IIS Rewrite Rules by using the below IIS features.
https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/importing-apache-modrewrite-rules
About how to convert the RewriteBase command.
https://forums.iis.net/t/1162790.aspx
Feel free to let me know if there is anything I can help with.

Upvotes: 1

Related Questions