We help IT Professionals succeed at work.
Troubleshooting Question

Simple web.config file not working

tonelm54
tonelm54 asked
on
23 Views
Last Modified: 2020-10-27
Ive just been forced to move from Apache to IIS by management cause IIS is apparently easier -> NO COMMENT

Ive pretty much done everything apart from translating my .htaccess file to web.config, all my .htaccess file does is redirect everything to index.php and then I deal with everything from there, so:-
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.css|\.js|\.ico)$
RewriteRule .* index.php/$0 [PT,L] 
Which I converted to:-
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
      <rewrite>
       <rules>
          <rule name="Main Rule" stopProcessing="true">
             <match url=".*" />
             <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
             </conditions>
             <action type="Rewrite" url="index.php/{R:0}" />
          </rule>
       </rules>
      </rewrite>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>
But when I run I get:-
Im a but lost as to where to go now, any ideas?
Comment
Watch Question

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Looks like you might be trying to convert a WordPress .htaccess file to IIS.

If this is true, it's unlikely this will work, as WordPress can write a modified .htaccess file at any time, under many circumstances.

If you're using WordPress, stick with Apache.

Author

Commented:
Its for developing my own web apps, unfortunately I have to use IIS 'as its easier for the team to support' and apparently Apache is too difficult (Ive been having this is an argument for over a year
now).

I did use a wordpress htaccess file as a template a while ago to do what I wanted using Apache. Basically i redirect all requests to index.php where i deal with authentication and then process the required page as needed. The only exception is images, javascrip and css pages which I serve directly.

Is it possible to do this in IIS???
Fractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
This is what I use

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="false" />
    <rewrite>
      <rules>
   <rule name="WordPress: https://mysite.com" patternSyntax="Wildcard">
    <match url="*" />
     <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     </conditions>
    <action type="Rewrite" url="index.php" />
   </rule></rules>
    </rewrite>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="FastCGI,RequestNotifications,RequestRouting,Module,Authentication,Security" verbosity="Verbose" />
                        <add provider="ISAPI Extension" areas="" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500,400" />
                </add>
            </traceFailedRequests>
        </tracing>
  </system.webServer>
</configuration>

Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
 unfortunately I have to use IIS ' 

I use IIS with PHP, Wordpress, Laravel and others and do not run into any issues.  There are advantages to using Windows and one of them is that is what your dev team is used to. For something very large, I know nginx can provide better performance. In most cases however, it is going to be hard to tell.