Page 1 of 1

IIS 7 & URL Rewrite

Posted: Fri Jan 23, 2009 11:09 am
by rokujou
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:

Code: Select all

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
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:

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>
Some brainstorming on this would be great, I'd really like to get it working, as I'm sure others would too.

Andy

Re: IIS 7 & URL Rewrite

Posted: Fri Jan 30, 2009 9:10 pm
by ruslany
Check this article: http://learn.iis.net/page.aspx/527/joomla-on-iis/. Specifically, make sure that in the "SEO Settings" on "Global configuration" page you set "Use Apache mod_rewrite" to "Yes".

Re: IIS 7 & URL Rewrite

Posted: Tue Feb 24, 2009 3:28 am
by jtalbot
ruslany wrote:Check this article: http://learn.iis.net/page.aspx/527/joomla-on-iis/. Specifically, make sure that in the "SEO Settings" on "Global configuration" page you set "Use Apache mod_rewrite" to "Yes".
Did that actually work for you? I can confirm rokujou 's two issues: either get 404's (if importing rules through the URL Rewrite module) or the content from the home page is always shown when navigating to other URL's.

I had started another thread at http://forum.joomla.org/viewtopic.php?f=544&t=374703 before finding this thread, but I guess we should continue the discussion here.

Re: IIS 7 & URL Rewrite

Posted: Tue Feb 24, 2009 6:23 pm
by ruslany
Yes, that worked for me. I've seen similar issues reported before and in those cases it turned out that the reason was that IIS7 was configured to run PHP either via ISAPI or via CGI. IIS7 needs to be configured to use FastCGI to run PHP. Is that how your IIS is configured?

Re: IIS 7 & URL Rewrite

Posted: Tue Feb 24, 2009 9:10 pm
by jtalbot
ruslany wrote:Yes, that worked for me. I've seen similar issues reported before and in those cases it turned out that the reason was that IIS7 was configured to run PHP either via ISAPI or via CGI. IIS7 needs to be configured to use FastCGI to run PHP. Is that how your IIS is configured?
Ah, you're right. It works now. I had tried the FastCGI before but I was getting weird results -- I was only getting the html text, with no color or styling. I've duplicated this again this time by turning off "Use Apache mod_rewrite" and having the rewrite rules in place. However, if I turn on "Use Apache mod_rewrite", then it all works fine: I get proper styling, I get the right URL's (without "index.php" in the address bar), and the right content is loaded. Fantastic!

Re: IIS 7 & URL Rewrite

Posted: Sat Feb 28, 2009 5:20 pm
by leonss
ok

Re: IIS 7 & URL Rewrite

Posted: Sat Sep 12, 2009 11:50 pm
by seeed
I have a similar issue. I'm using exactly the same settings but for some reason, my root won't load... I get a 404. All other files load fine (articles, etc)... it's just when I go to the my root domain.

For example http://www.Junk-Domains.com gives me a 404 error.

http://www.Junk-Domains.com/cool-jazz works beautifully.

Any ideas?

IIS 7/Joomla 1.5.14/latest PHP and FastCGI

Re: IIS 7 & URL Rewrite

Posted: Sat Oct 24, 2009 9:41 am
by Sophorth
Hi Seeed,

Your website does not have any default document defined when you type http://www.Junk-Domains.com

Please add the follow code below <system.webserver> in your web.config file:

<defaultDocument>
<files>
<clear />
<add value="index.php" />
<add value="Default.asp" />
<add value="Default.htm" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="default.aspx" />
</files>
</defaultDocument>

Hope this will work.

Re: IIS 7 & URL Rewrite

Posted: Mon Dec 06, 2010 8:41 pm
by ghostdlr
How can I set PHP to run with FastCGI and not ISAPI ?

Re: IIS 7 & URL Rewrite

Posted: Thu Apr 28, 2011 1:45 am
by randymir
I've been struggling with this for two days now. The code you have fixed it.

Randy

Re: IIS 7 & URL Rewrite

Posted: Tue May 03, 2011 1:36 pm
by gillianreynolds
Upgrading to IIS 7 should be rather transparent, unfortunately that is not the case when it comes to URL rewriting as we knew it from IIS 6.

Thanks!

Re: IIS 7 & URL Rewrite

Posted: Tue May 03, 2011 10:36 pm
by g1smd
Joomla 1.6.3 (onwards) now includes some sample code for URL rewriting with IIS.

Re: IIS 7 & URL Rewrite

Posted: Wed Sep 14, 2011 6:48 am
by Justinaschwarz
I've been struggling with this for two days now. The code you have fixed it. :D

Re: IIS 7 & URL Rewrite

Posted: Mon Nov 21, 2011 5:24 pm
by yommytec
@ ruslany I am having the same problem but I clicked on the link you gave unfortunately it is either down or outrightly no longer working. Can you please check the link?

P:S : Is there a place on this forum I can find people who can fully customize a Joomla blog for me? I need to sell the blog but it looks Ugly.

Re: IIS 7 & URL Rewrite

Posted: Sat Oct 20, 2012 7:22 pm
by g1smd
You've posted in the IIS7 thread, rather than an Apache thread.

Re: IIS 7 & URL Rewrite

Posted: Wed Nov 07, 2012 12:22 am
by g1smd
As soon as I see this

Code: Select all

(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$
I know it is a very old version of the code.

Get a newer copy of the IIS code from a more recent Joomla installer; do this even if you are continuing to use an old version of Joomla.


I guess I find it kind of suspicious that there is no redirect rule; meaning if I copy & paste a 're-written' URL, does't something have to tell the server that is a made-up URL, and it should be redirected to a real URL?
If there was a redirect, the URL shown in your browser address bar would change and the browser would make a new request for the new URL now shown. It would not be using the URL shown in the link you originally clicked on.

No. Instead, the server should be performing an internal rewrite. You ask for example.com/some-page and the server then internally and silently looks for /index.php?page=some-page or some such within the server without revealing the details of that internal path to the outside world.

Re: IIS 7 & URL Rewrite

Posted: Wed Apr 10, 2013 9:22 am
by simit
That looked promising, but it didn't work. Now I get 404's when I click on links. The url's still look right (as they did initially). The 404 says the physical path looks similar to the (rewritten) URL -- is that expected?