I'm using http://github.com/lakshmivyas/hyde to generate my website, and it included .htaccess mod_rewrite rules, but I'm going to be self-hosting my website on a Windows server using IIS, so I was trying to import the existing .htaccess rules into the IIS Rewrite module, but the rules it imported weren't working correctly.
Examples of the URLs I would like to rewrite are:
http://example.org.uk/about/
Rewrites to
http://example.org.uk/about/about.html
-----------
http://example.org.uk/blog/events/
Rewrites to
http://example.org.uk/blog/events.html
-----------
http://example.org.uk/blog/2010/11/foo-bar
Rewrites to
http://example.org.uk/blog/2010/11/foo-bar.html
The directories and file names are generic and could be any values. A copy of the .htaccess I use with Apache is the following.
# 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 have tried various ISAPI Rewrite modules but these haven't been successful, so I would prefer converting the rules to native IIS Rewrite rules. Any help getting this sorted is greatly appreciated.
EDIT:
I have solved 2/3 of the rules, it's just the following that I cannot seem to get working.
<rule name="Imported Rule 1" stopProcessing="false">
<match url="^([^/]+)/$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{R:0}/{R:1}.html" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:0}/{R:1}.html" />
</rule>
Which is mapping about/
to about/about.html
, it just continues showing a directory listing.