IIS 7 & URL Rewrite
Posted: Fri Jan 23, 2009 11:09 am
I've searched the forums and although there are a few URL rewrite questions I felt it would be better to ask my own as it's a little more detailed and specific.
I recently upgraded my server to Windows Server 2008 & IIS 7 with Microsoft's URL Rewrite Module. As a test, I imported the Joomla htaccess file into a new URL Rewrite rule and everything imported just fine with the exception of the following line:I immediately proceeded to my browser to test the rewriting rules only to find that I got a 404 error. Some checking showed me that my rules weren't matching correctly, though it was nothing to do with the fact that the line above was missing. After a quick browse to iis.net's 7 URL Rewrite Module forum I discovered there was an issue parsing {SCRIPT_NAME} and that, as a workaround, it should be replaced with {URL}
After doing this, I found that the rewrite rules were now working, but all apache style SEF urls would take me to my index page and not show the actual page. More clearly:
/index.php/about - takes me to my about page
/about, /services, /contact, etc - shows the homepage
Does anyone know why this could be happening? Also, what is the E=HTTP_AUTHORIZATION line supposed to do and could it be affecting the script?
For anyone's reference, the final URL Rewrite Module code is here:
Some brainstorming on this would be great, I'd really like to get it working, as I'm sure others would too.
Andy
I recently upgraded my server to Windows Server 2008 & IIS 7 with Microsoft's URL Rewrite Module. As a test, I imported the Joomla htaccess file into a new URL Rewrite rule and everything imported just fine with the exception of the following line:
Code: Select all
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
After doing this, I found that the rewrite rules were now working, but all apache style SEF urls would take me to my index page and not show the actual page. More clearly:
/index.php/about - takes me to my about page
/about, /services, /contact, etc - shows the homepage
Does anyone know why this could be happening? Also, what is the E=HTTP_AUTHORIZATION line supposed to do and could it be affecting the script?
For anyone's reference, the final URL Rewrite Module code is here:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{QUERY_STRING}" pattern="mosConfig_[a-zA-Z_]{1,21}(=|\%3D)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="base64_encode.*\(.*\)" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="(\<|%3C).*script.*(\>|%3E)" />
<add input="{QUERY_STRING}" pattern="GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
<add input="{QUERY_STRING}" pattern="_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ignoreCase="false" />
</conditions>
<action type="CustomResponse" url="index.php" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="Imported Rule 2">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" negate="true" pattern="^/index.php" ignoreCase="false" />
<add input="{URL}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Andy