Sunday, June 08, 2008

Getting Joomla sh404SEF To Work On Microsoft IIS

I was working with a 1.0 version of Joomla and wanted to get the sh404SEF module to work with IIS. It wasn't easy, but in the end, I got it all working as though it were running under Linux Apache.

Here's a few things I did to make this happen:

  • Made sure the global config option in Joomla for Search Engine Friendly URLs was turned on.
  • Installed the Ionic's Isapi Rewrite Filter for IIS. This filter gives IIS rewrite capabilities that basically match that of mod_rewrite. Install instructions can be found here.
  • Installed the rewrite rules mentioned here in IsapiRewrite4.ini.
  • Added these additional rules to IsapiRewrite4.ini:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_URL} ^(/component/option,com) [OR]
    RewriteCond %{HTTP_URL}      ^.*[.]html.*$
    RewriteRule ^(.*) /index.php [QSA,L,U]
    
  • In the sh404SEF configuration, advanced section, I chose:
      Rewrite mode:  with .htaccess (mod_rewrite)
    
  • Now here was the really tricky part. In apache, if you rewrite a URI from:
      /Learn-About-My-App
    
    to:
      /doc?title=Learn-About-My-app
    
    the environment variable REQUEST_URI stays /Learn-About-My-App. In IIS, REQUEST_URI is updated to /doc?.... The result? sh404SEF won't work with IIS. To fix this, I made the following the very first line of code in components/com_sef/sef.php:
      $_SERVER['REQUEST_URI'] = isset($_SERVER['HTTP_X_REWRITE_URL']) ? 
         $_SERVER['HTTP_X_REWRITE_URL'] : $_SERVER['REQUEST_URI'] ;
    

Good luck getting IIS to play nice with Joomla - I've learned first hand, you're going to need it.

4 comments:

  1. Anonymous1:40 PM

    hi...I am running plesk and it already has a ISAPI filter...in that case, what do I do? SHould I remove that ISAPI (urlprotect.dll) and install IIRF? thanks...

    ReplyDelete
  2. Usha -

    I wish I had some sagely advice for you on this, but I really don't.

    I'd probably try to install IIRF, but that may not be the best approach.

    ReplyDelete
  3. Anonymous4:14 PM

    In the sh404SEF configuration, advanced section? Where is this? What file?

    ReplyDelete
  4. Anonymous12:25 AM

    http://www.codeplex.com/IIRF/Wiki/View.aspx?title=Joomla&referringTitle=Home

    ReplyDelete