0
我使用http://github.com/lakshmivyas/hyde來生成我的網站,它包括.htaccess mod_rewrite規則,但是我將在使用IIS的Windows服務器上自我託管我的網站,所以我是試圖將現有的.htaccess規則導入到IIS Rewrite模塊中,但它導入的規則無法正常工作。我想重寫URL的將mod_rewrite規則轉換爲IIS重寫規則
的例子是:
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
的目錄和文件名是通用的,可以是任何值。我使用Apache的.htaccess的副本如下。
# 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
我曾嘗試過各種ISAPI重寫模塊,但這些都沒有成功,所以我寧願轉換規則爲本地IIS重寫規則。任何幫助獲得這種排序非常感謝。
編輯:
我已經解決了規則的2/3,這只是我似乎無法獲得工作如下。
<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>
這是映射到about/
about/about.html
,它只是繼續呈現出目錄列表。