IIS 7 & URL Rewrite

This forum is for issues with installing Joomla! on IIS webservers.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
rokujou
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Mon Aug 18, 2008 2:37 pm

IIS 7 & URL Rewrite

Postby rokujou » 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:

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="(\&lt;|%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

ruslany
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Jan 30, 2009 9:07 pm

Re: IIS 7 & URL Rewrite

Postby ruslany » Fri Jan 30, 2009 9:10 pm

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".

jtalbot
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Mon Jan 26, 2009 3:44 am

Re: IIS 7 & URL Rewrite

Postby jtalbot » Tue Feb 24, 2009 3:28 am

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 viewtopic.php?f=544&t=374703 before finding this thread, but I guess we should continue the discussion here.

ruslany
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Jan 30, 2009 9:07 pm

Re: IIS 7 & URL Rewrite

Postby ruslany » Tue Feb 24, 2009 6:23 pm

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?

jtalbot
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Mon Jan 26, 2009 3:44 am

Re: IIS 7 & URL Rewrite

Postby jtalbot » Tue Feb 24, 2009 9:10 pm

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!

leonss
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Feb 28, 2009 5:02 pm
Contact:

Re: IIS 7 & URL Rewrite

Postby leonss » Sat Feb 28, 2009 5:20 pm

ok

seeed
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Sep 12, 2009 11:48 pm

Re: IIS 7 & URL Rewrite

Postby seeed » Sat Sep 12, 2009 11:50 pm

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

Sophorth
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Fri Oct 23, 2009 9:39 am

Re: IIS 7 & URL Rewrite

Postby Sophorth » Sat Oct 24, 2009 9:41 am

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.

ghostdlr
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Mar 12, 2010 2:25 pm

Re: IIS 7 & URL Rewrite

Postby ghostdlr » Mon Dec 06, 2010 8:41 pm

How can I set PHP to run with FastCGI and not ISAPI ?

randymir
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Sun Apr 10, 2011 10:39 pm

Re: IIS 7 & URL Rewrite

Postby randymir » Thu Apr 28, 2011 1:45 am

I've been struggling with this for two days now. The code you have fixed it.

Randy

User avatar
gillianreynolds
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Tue May 03, 2011 1:32 pm
Location: California
Contact:

Re: IIS 7 & URL Rewrite

Postby gillianreynolds » Tue May 03, 2011 1:36 pm

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!
Please read forum rules regarding the use of signatures: viewtopic.php?f=8&t=65

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: IIS 7 & URL Rewrite

Postby g1smd » Tue May 03, 2011 10:36 pm

Joomla 1.6.3 (onwards) now includes some sample code for URL rewriting with IIS.
Online since 1995.

Justinaschwarz
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Sep 13, 2011 7:07 am

Re: IIS 7 & URL Rewrite

Postby Justinaschwarz » Wed Sep 14, 2011 6:48 am

I've been struggling with this for two days now. The code you have fixed it. :D

yommytec
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Nov 19, 2011 7:29 pm

Re: IIS 7 & URL Rewrite

Postby yommytec » Mon Nov 21, 2011 5:24 pm

@ 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.
Last edited by ooffick on Thu Mar 15, 2012 10:29 pm, edited 1 time in total.
Reason: Mod Note: Removed manual Signature. Please read the Forum rules for details.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: IIS 7 & URL Rewrite

Postby g1smd » Sat Oct 20, 2012 7:22 pm

You've posted in the IIS7 thread, rather than an Apache thread.
Online since 1995.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: IIS 7 & URL Rewrite

Postby g1smd » Wed Nov 07, 2012 12:22 am

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.
Online since 1995.

simit
I've been banned!
Posts: 33
Joined: Tue Apr 09, 2013 10:42 am

Re: IIS 7 & URL Rewrite

Postby simit » Wed Apr 10, 2013 9:22 am

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?


Return to “Joomla! 1.5 on IIS webserver”

Who is online

Users browsing this forum: No registered users and 1 guest