0

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

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.