I am trying to build a MVC app in php in windows server.
My app is working in Linux/Apache with .htaccess file and I am trying to create a web.config file to work with Windows IIS but I can not make it work.
My app's structure is
/app
/public
.htaccess
My basic .htaccess
file redirect to /public
folder
# Base .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Inside app folder I have an .htaccess
file .
# app folder Options -Indexes
Inside public I redirect everything through index.php file with url parameters
# public folder
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
I tried to translate .htaccess through importing tool in URL rewrite and the result is returning 500 error
This is what i get for base rule
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^$" ignoreCase="false" />
<action type="Rewrite" url="public/" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<action type="Rewrite" url="public/{R:1}" />
</rule>
</rules>
</rewrite>
The one inside app folder does not give me any results for Options -Indexes
And this one is for redirecting to index.php from public folder
<rewrite>
<!--This directive was not converted because it is not supported by IIS: RewriteBase /public.-->
<rules>
<rule name="Imported Rule 3" stopProcessing="true">
<match url="^(.+)$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
Any ideas to resolve this 500 error ? is something in web.config file but I dont know much of IIS.
Any though would be helpful. TIA
Any ideas to resolve this 500 error ? is something in web.config file but I dont know much of IIS.
As far as I know, the IIS url rewrite rule doesn't contains the same setting like "RewriteBase /public" in .htaccess.
The IIS's rewriteBase is auto-calculated based on where the rule is defined - so, if you define the rule under the /pubic folder(path) in your site, that becomes the base for those rules.
So there is no need to set the rewrite base in the url rewrite in the web.config file if you put a special web.config file inside the publc folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.