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>

1 Answer

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.

About how to convert the RewriteBase command.

Feel free to let me know if there is anything I can help with.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest