【问题标题】:Simple mod rewrite based on a working web.config基于工作 web.config 的简单 mod 重写
【发布时间】:2015-05-25 17:15:25
【问题描述】:

对于导航到 link.html 以重定向到 index.php/link/ 的人来说,这是一个简单的重定向,同时仍保持任何查询字符串不变。

以下在 web.config 文件中使用 IIS7 的环境中完美运行。

<rule name="Rewrite for link.html">
    <match url="link.html" />
    <action type="Rewrite" url="index.php/link/" />
</rule>
<rule name="Rewrite CI Index">
    <match url=".*" />
    <conditions>
        <add input="{REQUEST_FILENAME}" pattern="css|js|jpg|jpeg|png|gif|ico|htm|html|ttf|eot" negate="true" />
        <add input="{REQUEST_FILENAME}" pattern="admin.php" negate="true" />
        <add input="{REQUEST_FILENAME}" pattern="index.php" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php/{R:0}" />
</rule>

我有另一个 IIS 平台,它使用类似于 Apache 的 mod_rewrite 的插件

什么是 RewriteCond / RewriteRule 语法来做类似上面的例子?到目前为止,我所有的猜测都以不同的方式被炸毁了。

这是现有的 IIRF.ini 文件,它可以很好地执行重写 CI 索引:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

问题是如何让 link.html 的重写以适应这种类似 apache 的语法。

TIA 寻求帮助。

【问题讨论】:

    标签: mod-rewrite web-config iirf


    【解决方案1】:

    只需在 RewriteCond/RewriteRule 块之前添加重定向规则:

    RedirectRule ^link.html(.*)$ /index.php/link/$1
    

    【讨论】:

    • 把它放在首位工作:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} ^/link\.html RewriteRule ^.*$ /index.php/link [L]
    • 我以为你想重定向,而不是重写。顺便说一句,您实际上并不需要RewriteConds,只需输入RewriteRule ^/link\.html$ /index.php/link [L,I](我建议还添加[I] 标志以进行不区分大小写的匹配)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2010-09-23
    相关资源
    最近更新 更多