Actions

Difference between revisions of "Enabling Search Engine Friendly (SEF) URLs on IIS"

From Joomla! Documentation

m (Addition of IIS7 rewrite method)
(Added web.config for IIS7)
Line 1: Line 1:
 +
==IIS 7 URL Rewriting==
 +
If you have a server running IIS 7 and PHP, you can take advantage of IIS's own internal URL rewriting by using a web.config file similar to the one listed below.
 +
This has been tested on Joomla 1.5 with IIS 7 on Windows Server 2008 with no problems so far. For more information on converting .htaccess to web.config, check out http://learn.iis.net/page.aspx/557/translate-htaccess-content-to-iis-webconfig/
 +
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<configuration>
 +
    <system.webServer>
 +
        <rewrite>
 +
            <rules>
 +
                <rule name="Joomla Main Rewrite Rule">
 +
                    <match url="(.*)" ignoreCase="true" />
 +
                    <action type="Rewrite" url="index.php/" />
 +
                    <conditions>
 +
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
 +
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
 +
                        <add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
 +
                     
 +
                    </conditions>
 +
                </rule>
 +
                <rule name="Joomla Search Rule">
 +
                    <match url="(.*)" ignoreCase="true" />
 +
                    <conditions>
 +
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
 +
                    </conditions>
 +
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
 +
                </rule>
 +
            </rules>
 +
        </rewrite>
 +
        <caching>
 +
            <profiles>
 +
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
 +
            </profiles>
 +
        </caching>
 +
    </system.webServer>
 +
</configuration>
 +
</source>
 +
 +
 +
==Helicon ISAPI Rewrite==
 
Helicon ISAPI Rewrite 3 located at http://www.helicontech.com/isapi_rewrite/ now provides near identical mod_rewrite functionality.
 
Helicon ISAPI Rewrite 3 located at http://www.helicontech.com/isapi_rewrite/ now provides near identical mod_rewrite functionality.
  

Revision as of 10:16, 4 December 2009

IIS 7 URL Rewriting

If you have a server running IIS 7 and PHP, you can take advantage of IIS's own internal URL rewriting by using a web.config file similar to the one listed below. This has been tested on Joomla 1.5 with IIS 7 on Windows Server 2008 with no problems so far. For more information on converting .htaccess to web.config, check out http://learn.iis.net/page.aspx/557/translate-htaccess-content-to-iis-webconfig/

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Joomla Main Rewrite Rule">
                    <match url="(.*)" ignoreCase="true" />
                    <action type="Rewrite" url="index.php/" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
 
                    </conditions>
                </rule>
                <rule name="Joomla Search Rule">
                    <match url="(.*)" ignoreCase="true" />
                    <conditions>
                        <add input="{URL}" pattern="^/search.php" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="/index.php?option=com_content&amp;view=article&amp;id=4" />
                </rule>
            </rules>
        </rewrite>
        <caching>
            <profiles>
                <add extension=".php" policy="DisableCache" kernelCachePolicy="DisableCache" />
            </profiles>
        </caching>
    </system.webServer>
</configuration>


Helicon ISAPI Rewrite

Helicon ISAPI Rewrite 3 located at http://www.helicontech.com/isapi_rewrite/ now provides near identical mod_rewrite functionality.

IIS 7 has its own rewrite module now, the URL Rewrite which works excellent and doesn't require third party installs. It can be enabled through the Web Platform Installer. In the Joomla config turn on both the SEF and Apache mod_rewrite, next create a rule under IIS URL Rewrite: Pattern field: ^([^/]+)/?$ Ignore case ON Action type: Rewrite Rewrite URL: index.php/


The default rewrite rules can be used and the following code inserted to the top of the index.php file:

if (isset($_SERVER['HTTP_X_REWRITE_URL']))
{
    $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}



First job is to install ISAPI rewriter of your choice http://www.isapirewrite.com/ or http://cheeso.members.winisp.net/IIRF.aspx

ISAPI ReWrite has a lite version (limited) and IIRF (IonicIsapiRewriter) is freeware always updated and the source is free!

Both are configured via file IsapiRewrite4.ini (you dont need to worry about .htaccess.txt ignore it).

The following entries for ISAPI REWRITE:

RewriteLog  D:\temp\iirfLog.out
RewriteLogLevel 3
 
IterationLimit 10
 
# Joomla/Mambo rewrite rules
RewriteRule  ^/$                      /index.php
RewriteRule ^/content/blogsection/([^/]+)/([^/]+)/ /index.php?option=com_content&task=blogsection&id=$1&Itemid=$2
RewriteRule ^/content/blogcategory/([^/]+)/([^/]+)/ /index.php?option=com_content&task=blogcategory&id=$1&Itemid=$2
RewriteRule ^/content/section/([^/]+)/([^/]+)/ /index.php?option=com_content&task=section&id=$1&Itemid=$2
RewriteRule ^/component/option,([^/]+)/([^/]+),([^/]+)/([^/]+),([^/]+)/([^/]+),([^/]+) /index.php?option=$1&$2=$3&$4=$5&$6=$7
RewriteRule ^/component/option,([^/]+)/([^/]+),([^/]+)/([^/]+),([^/]+) /index.php?option=$1&$2=$3&$4=$5
RewriteRule ^/component/option,([^/]+)/([^/]+),([^/]+)/ /index.php?option=$1&$2=$3
RewriteRule ^/content/category/([^/]+)/([^/]+)/([^/]+)/ /index.php?option=com_content&task=category&sectionid=$1=&id=$2&Itemid=$3
RewriteRule ^/content/view/([^/]+)/([^/]+)/([^/]+)/([^/]+)/ /index.php?option=com_content&task=view&id=$1&Itemid=$2&limit=$3&limitstart=$4
RewriteRule ^/content/view/([^/]+)/([^/]+)/ /index.php?option=com_content&task=view&id=$1&Itemid=$2

The following is for IonicIsapiRewriter:

IterationLimit 10

Tested and working with ARTIO JoomSEF:

RewriteCond %{HTTP_URL}             (/|\.htm|\.php|\.html|/[^.]*)$   
RewriteCond %{REQUEST_FILENAME}     !-f
RewriteCond %{REQUEST_FILENAME}     !-d
RewriteRule (.*)                /index.php                      [U,L]RewriteCond %{HTTP_URL}             (/|\.htm|\.php|\.html|/[^.]*)$   
RewriteCond %{REQUEST_FILENAME}     !-f
RewriteCond %{REQUEST_FILENAME}     !-d
RewriteRule (.*)                /index.php                      [U,L]
MaxMatchCount 10

Tested and working with default Joomla SEO:

RewriteRule ^/$                      /index.php
RewriteRule ^/content/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/ /index.php?option=com_content&task=$1&id=$2&Itemid=$3&limit=$4&limitstart=$5
RewriteRule ^/content/([^/]+)/([^/]+)/([^/]+)/ /index.php?option=com_content&task=$1&id=$2&Itemid=$3
RewriteRule ^/component/option,([^/]+)/([^/]+),([^/]+)/([^/]+),([^/]+)/([^/]+),([^/]+) /index.php?option=$1&$2=$3&$4=$5&$6=$7
RewriteRule ^/component/option,([^/]+)/([^/]+),([^/]+)/ /index.php?option=$1&$2=$3

Tested and working with sh404SEF:

RewriteLogLevel 4 #Make it 0 in to turn debugging off
RewriteLog c:\IIRfLogfile.log #Write the absolute path of your file here 
 
MaxMatchCount 10
 
# don't rewrite any request that goes to administrator
RewriteRule ^/administrator   -   [L]
 
RewriteCond %{HTTP_URL} (/|\.htm|\.php|\.html|!administrator|/[^.]*)$  
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php [U,L]

Other Third party SEO should work once to follow there rewrite conditions/rules. I run IonicIsapiRewriter-1.2.12b the betas are rock solid and I use it on my production servers with no issues. Please follow vendors installation instructions to get the ISAPI filter working on your IIS server.