In the old Apache hosting, we had the following .htaccess
file inside public_html/adm
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /adm/index.php [L]
</IfModule>
This is supposed to redirect every url after the adm
subdir to the /adm/index.php
file, if the path does not exist. And works just fine.
Then I migrated this website to IIS (v8.5), and using the "Import Rules..." tool, I attempted to achieve the same effect, but at first it was messing with urls other than those under the /adm
path. In an attempt to overcome this, I changed the original .htaccess
file slightly, like below:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond adm/%{REQUEST_FILENAME} !-f
RewriteCond adm/%{REQUEST_FILENAME} !-d
RewriteRule adm/. /adm/index.php [L]
</IfModule>
The resulting IIS rules are as follows:
<rewrite>
<rules>
<rule name="Imported Rule 1" enabled="true" stopProcessing="true">
<match url="adm/." ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="adm/{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="true" negate="true" />
<add input="adm/{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="/adm/index.php" />
</rule>
</rules>
</rewrite>
At first it seemed to work(1), but I quickly noticed that valid paths are being redirected as well(2). How can to make it work properly?
http://example.com/aaaa
returns 404 error, andhttp://example.com/adm/aaaa
returns the contents ofhttp://example.com/adm/index.php
(this is expected).http://example.com/adm/images/logo.png
, which is a valid path, returns the contents of the index.php file (this is mistaken).
This is the result of the Rewrite Rules from the web.config
file.
Thanks.