Search code examples
phpiismodel-view-controllerweb-config

The files are not loading in MVC framework in IIS server


My first time using mvc framework on a iis server. I changed the .htaccess to web.config and very strange things are happening. some .css and .js files are loaded, some are not. I totally don't get it. For example these files load correctly:

<script src="/assets/plugins/global/plugins.bundle.js"></script>
<script src="/assets/js/scripts.bundle.js"></script>

But for example this file is not loading:

<script src="/assets/js/custom/authentication/sign-in/general.js"></script>

my folders look like this:

-wwwroot
 web.config
   -public
      -assets
        -js
          -...

Maybe there is a problem in the configuration file. If I write name of folder / public / before the address to the .js files, then everything is good. Maybe some of you had a similar problem and know how to solve it Below is my configuration file code:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="false" />
    <rewrite>
      <rules>
        <rule name="rule 1p" stopProcessing="true">
          <match url="^$"/>   
            
          <action type="Rewrite" url="public/" />
        </rule>
        <rule name="rule 2p" stopProcessing="true">
          <match url="^(.*)$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Rewrite" url="public/index.php?{R:1}" appendQueryString="true"/>
        </rule>
        <rule name="phpmyadmin" stopProcessing="true">
            <match url="(.*)phpmyadmin(.*)" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

EDIT

I changed physical path on the server to: C:\inetpub\wwwroot\public and also replace web.config to public folder

-wwwroot
   -public
     -web.config
      -assets
        -js
          -...

my web.congif file :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="rule 1p" stopProcessing="true">
                  <match url="^(.+)/$"/>
                  <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                  </conditions>          
                  <action type="Rewrite" url="/{R:1}" />
                </rule>
                <rule name="Rule" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

The only problem I have right now is that the main page is not showing up. All subpages work properly, including js and css files. when i want to display my home page ex. mypage.com then i get such an error:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory. Detailed Error Information: Module DirectoryListingModule Notification ExecuteRequestHandler Handler
StaticFile Error Code 0x00000000 Requested URL localhost
Physical Path C:\inetpub\wwwroot\public Logon Method Anonymous Logon User Anonymous

when I want to display the home page after by mypage.com/home/index then the page is displayed but without js and css files


Solution

  • This problem may occurs because the website doesn't have the Directory Browsing feature enabled. To resolve this problem,you can try use the following methods:

    1. Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
    2. In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
    3. In the Features view, double-click Directory Browsing.
    4. In the Actions pane, select Enable.