views:

882

answers:

4

I am used to working with Apache servers, so when mod_rewrite is enabled, I can create an htaccess file and use URL rewriting.

Here's my htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Now I've built this site that uses this URL rewriting module but I have come to learn that it is a Microsoft server. Can I use my htaccess file? Is there something I need to change to get it to work? How can I tell if URL rewriting is set up on the Microsoft server?

+3  A: 

The .htaccess file is an Apache convention for providing end-user access to Apache configuration, so you're not going to be able to use it as a drop in replacement on an IIS (Microsoft) server. You would be able to use it if you were running Apache on Windows.

IIS7 has a URL rewriting module that offers support for rewriting URLs. There's also the ISAPI_Rewrite product which does the same for previous versions of IIS. You'll likely need some level of administrative permissions on the server to use either of these modules (i.e., no htaccess-like mechanism)

Alan Storm
A: 

You may use your above config as is in ISAPI_Rewrite 3 or Helicon Ape products.

TonyCool
+1  A: 

If you use IIS 7 then you can use IIS URL Rewrite Module, that has an "Import Rules" feature that can be used to translate mod_rewrite rules to IIS URL rewrite format. These particular rewrite rules will not translate because the RewriteCond uses the "-s" and "-l" flags which check if the requested URL corresponds to a non-zero size file or to a symbolic link on a file system. If your application does not use any symbolic links then you can safely replace these conditions with:

RewriteCond %{REQUEST_FILENAME} -f [OR]

and then convert the rules by using IIS URL Rewrite UI. That will result in these rules:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^.*$" />
      <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_FILENAME}" matchType="IsFile"  />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory"  />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^.*$" />
      <action type="Rewrite" url="index.php" />
    </rule>
  </rules>
</rewrite>
RuslanY
+1  A: 

You can use your configuration as is, in Ionic's Isapi Rewrite Filter (IIRF).

IIRF is free, open-source.

Cheeso
good to hear there is a free, open-source version
Andrew