首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将mod_rewrite规则转换为mod_rewrite规则

将mod_rewrite规则转换为mod_rewrite规则
EN

Stack Overflow用户
提问于 2010-09-26 22:42:46
回答 1查看 1.1K关注 0票数 0

我正在使用http://github.com/lakshmivyas/hyde生成我的网站,其中包括.htaccess mod_rewrite规则,但我将使用IIS在Windows服务器上自托管我的网站,所以我试图将现有的.htaccess规则导入到IIS重写模块中,但它导入的规则不能正常工作。

我想重写的URL示例如下:

代码语言:javascript
复制
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的副本。

代码语言:javascript
复制
# 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的规则,只是下面这些我似乎无法开始工作。

代码语言:javascript
复制
            <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,它只是继续显示目录列表。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-26 21:33:29

我总是尽量避免这样的情况。因此,我只需使用URL重写器,它允许我在Apache规则使用IIS时粘贴这些规则。那就是ISAPI_Rewrite 3(精简版是免费的),或者Ape,它对3个或更少的网站也是免费的。从那以后我就再也没有像你这样头疼过。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3798268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档