Joomla Search Engine Friendly URLs issue on IIS7

friendly-urliisiis-7joomlaseo

I have Joomla 1.5.9 running with php 5.2.8, mySQL 5.1.31 on IIS7 on a vista 64 dev box. I have both SEO Settings "Search Engine Friendly URLs" and "Use Apache mod_rewrite" working correctly.

I'm also setting up a hosted site (with www.mochahosting.com). They use slightly older versions of the same software: Joomla 1.5.5, php 5.2.6, mySQL 5.0.4x. They also use IIS7, but running on Windows 32.

I can't get either of the SEO settings to work on the hosted site (I have gotten the SEO settings to work on my local machine, with pretty much the same configuration). Let's start with "Search Engine Friendly URLs" only to keep things simple.

Also, I don't yet have a domain name, so I use a hosts file alias to get to the site. I don't expect anyone to go through that trouble to answer my question, so I'll just describe the issue and hope I do a good enough job that people can understand what's going on. I'll use http://nodomainyet.com/joomla156_mx as the base URL (i.e., the joomla home page) for the purpose of this question. Yes, this does imply that Joomla is installed in a subdirectory — I'm not sure if this is a problem or not (it's not a problem on my dev box).

On to the problem.

Turning on "Search Engine Friendly URLs" causes http://nodomainyet.com/joomla156_mx to generate a 404 ("Component not found"). In the 404 error page there is a link that goes to http://nodomainyet.com/joomla156_mx/index.php — and that link works. If I turn off "Search Engine Friendly URLs" then both http://nodomainyet.com/joomla156_mx and http://nodomainyet.com/joomla156_mx/index.php work. So it seems that turning on "Search Engine Friendly URLs" causes the "automatic redirecting" of http://nodomainyet.com/joomla156_mx to http://nodomainyet.com/joomla156_mx/index.php to stop working…

Now, if I go to http://nodomainyet.com/joomla156_mx/index.php and from there navigate to the various main menu links (I'm only using the default joomla site that gets installed with a new Joomla instance), then everything works fine. It's just going to http://nodomainyet.com/joomla156_mx that doesn't work. It's worth noting that the "home" link that's in the main menu goes to http://nodomainyet.com/joomla156_mx by default.

I've compared the output of phpinfo on the host to that of my dev box and couldn't see any differences that would cause this issue…

Turning on the second SEO setting — "Use Apache mod_rewrite" — does not solve the problem (one would think that it might, since the purpose of that setting is to get rid of index.php in the URL).

The "Search Engine Friendly URLs" usually seems pretty trivial to get to work — it doesn't require a web.config and rewrite rules… I'm not sure what could possibly cause it to go wrong.


Update – 2009-03-03

I thought maybe it was a bad idea to only turn on the first SEO setting ("Search Engine Friendly URLs") from ("Use Apache mod_rewrite") (even though I can just turn on "Search Engine Friendly URLs" by itself on my local machine and it works fine). So I tried a few more experiments

I thought perhaps the problem was that URL rewriting wasn't setup properly in IIS7 on the host. I did the (first) test file described in http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module and that worked — so that means URL rewriting is working.

Then I thought perhaps the problem is that the rewrite rules that one sees everywhere for Joomla on IIS7 need to be rewritten to take into account the subdirectory. Like I said above, the SEO settings are working fine on my local machine. Joomla is also installed in a subdirectory, and everything is working fine. Nevertheless, I tried to modify the rewrite rule from

<rewrite>
    <rules>
        <rule name="Imported Rule 1" enabled="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
                <add input="{SCRIPT_NAME}" negate="true" pattern="^/index.php" ignoreCase="false" />
                <add input="{SCRIPT_NAME}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
            </conditions>
            <action type="Rewrite" url="index.php" />
        </rule>
    </rules>
</rewrite>

to

<rewrite>
    <rules>
        <rule name="Imported Rule 1" enabled="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
                <add input="{SCRIPT_NAME}" negate="true" pattern="^/joomla156mx/index.php" ignoreCase="false" />
                <add input="{SCRIPT_NAME}" pattern="(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$" />
            </conditions>
            <action type="Rewrite" url="joomla156mx/index.php" />
        </rule>
    </rules>
</rewrite>

(i.e., prepending the directory name to the condition and action). That didn't make a difference. Now, I'm completely new to rewrite rules so I might have screwed up something.

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? But, again, this is all working fine on my local box with plain old rewrite rules, so I may be barking at the wrong tree.

Thanks for the help!

Best Solution

The last steps on this page walk through Enabling Search Engine Friendly URLs.

By default Joomla uses query string parameters for all the links URLs it generates for your web site. This behavior can be changed by enabling what is called "Search Engine Friendly URLs" in Joomla. However, this feature relies on the URL rewriting functionality to be available on the web server. IIS 6.0 does not have URL rewriting capabilities, so you could use one of the third party URL rewriting products, such as ISAPI_Rewrite or Ionics ISAPI Rewrite Filter. IIS 7.0 has URL rewriting support, which can be enabled by installing Microsoft URL Rewrite Module for IIS 7.0. The following instructions describe how URL Rewrite Module for IIS 7.0 can be used to enable Clean URLs in Joomla.
First, you will need to download and install Microsoft URL Rewrite Module. Once it has been installed, create and open a web.config file located in C:\inetpub\wwwroot\Joomla folder. Paste the following XML code into this file.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Security Rule" 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="SEO Rule">
          <match url="(.*)" ignoreCase="false" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" pattern="" ignoreCase="false" />
            <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" />
        </rule>
      </rules>
    </rewrite>
 </system.webServer>
</configuration>

Save the web.config file and then open web browser and logon to the Joomla administrator console at http://localhost/joomla/administrator/ . Once logged on, go to Site --> Global Configuration menu configure SEO settings as below:

  • Search Engine Friendly URLs - Yes
  • Use Apache mod_rewrite - Yes
  • Add suffix to URLs - No
  • Save configuration by clicking on "Apply" and then browse to http://localhost/joomla/ . You will see that now all links in Joomla pages have URLs without query string parameters and if you click on any of these links the server will return correct response:

    Related Question