Skip to main content

Enabling Search Engine Friendly (SEF) URLs on IIS

When working with IIS7, you can enable Search Engine Friendly (SEF) URLs by utilizing the native URL Rewrite module. This module allows you to define rules in a site's web.config file, using XML format. To convert .htaccess rules to the web.config format, follow the steps below.

For IIS6, a third-party add-on such as the one provided by Helicon must be used to directly support .htaccess rules.

IIS7

If you are running IIS 7 with PHP, you can leverage IIS's internal URL rewriting capabilities by using a web.config file similar to the example provided below.

You have two options to create the file:

  1. You can manually create the web.config file.
  2. You can use the graphical user interface (GUI) in the IIS7 Manager, which allows you to import .htaccess rules using the GUI wizard.

Please note that the availability of this functionality depends on the presence of the IIS URL Rewrite Module. This module is not included with Windows by default, but it can be downloaded for free from Microsoft.

GUI

If the IIS URL Rewrite module is installed, you can access the URL Rewrite tool through the IIS Manager's interface. It will be listed under the configurable IIS modules for your website. The interface provides self-explanatory options and supports regular expressions, wildcards, and exact matches.

To enable SEF URLs in the Origen config, make sure both the SEF and Apache mod_rewrite are turned on. Then, create a rule under IIS URL Rewrite with the following settings:

Pattern field: ^([^/]+)/?$ Ignore case: ON Action type: Rewrite Rewrite URL: index.php/

web.config

The provided instructions have been tested on Origen 4.0.1 with IIS 7 on Windows Server 2008 without any reported issues. For more detailed information on converting .htaccess rules to web.config, refer to the Translate .htaccess Content to IIS web.config article.

<?xml version="1.0" encoding="UTF-8"?/>
<configuration/>
<system.webServer/>
<rewrite/>
<rules/>
<clear />
<rule name="Common Exploit Blocking" stopProcessing="true"/>
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAny"/>
<add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" />
<add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" />
<add input="{QUERY_STRING}" pattern="(\&amp;lt;|%3C).*script.*(\/>|%3E)" />
<add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" />
<add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" />
</conditions/>
<action type="Redirect" url="index.php" appendQueryString="false" redirectType="SeeOther" />
</rule/>
<rule name="Origen Search Rule" stopProcessing="true"/>
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll"/>
<add input="{URL}" pattern="^/search.php" ignoreCase="true" />
</conditions/>
<action type="Rewrite" url="/index.php?option=app_myapp&amp;amp;task=read&amp;amp;id=4" />
</rule/>
<rule name="Origen Main Rewrite Rule" stopProcessing="true"/>
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll"/>
<add input="{URL}" pattern="(/[^.]*|\.(php|html?|feed|pdf|raw))$" />
<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/>
<caching/>
<profiles/>
<add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles/>
</caching/>
</system.webServer/>
</configuration/>