Search code examples
mod-rewriteweb-configiirf

Simple mod rewrite based on a working web.config


Its a simple redirect for someone navigating to link.html to get redirected to index.php/link/ while still keeping any query string intact.

Below works perfectly in an environment that uses IIS7 in the web.config file.

<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>

I have another IIS platform that uses a plugin that acts like Apache's mod_rewrite

What's the RewriteCond / RewriteRule syntax to do something like the example above? All of my guesses blown up in different ways so far.

Here's the existing IIRF.ini file that does the Rewrite CI Index just fine:

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

The question is how to get the Rewrite for link.html to fit in with this apache like syntax.

TIA for any help.


Solution

  • Just add a redirect rule before the RewriteCond/RewriteRule block:

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