Convert Old .htaccess rules to IIS Rewrite Rules

.htaccessiis-7

I've started to host my own site on IIS and it was previously hosted on DreamHost on Apache so I have an .htaccess file with rewrite rules I would like to convert to the URL Rewrite module rules.

# initialize mod_rewrite
RewriteEngine on
RewriteBase /

# remove the www from the url
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

###  BEGIN GENERATED REWRITE RULES  ####

RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*) $1/index.html

####  END GENERATED REWRITE RULES  ####

# listing pages whose names are the same as their enclosing folder's
RewriteCond %{REQUEST_FILENAME}/$1.html -f
RewriteRule ^([^/]*)/$ %{REQUEST_FILENAME}/$1.html

# regular pages
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^.*$ %{REQUEST_FILENAME}.html

# set our custom 404 page
ErrorDocument 404 /404.html

I'm using the application Hyde to generate my static site, so would like to get this working if possible. I've tried importing the htaccess but the rules do not seem to give the right outcome.

Best Answer

If you want to just dump your .htaccess into your root folder and have IIS obey your rewrite rules, there's a plugin called ISAPI Rewrite. We use the paid version but the free version should do you just fine if it's just one website.

The IIS7 rewrite syntax is (obviously) totally different, and I don't know if any tools exist.

Related Topic