Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS document root in subfolder

Hey, I have a PHP Windows Azure project but I am new to IIS. I have my PHP libs in root folder and client files like index.php, style sheets or javascripts in a subfolder called document_root.

How can I set up IIS 7 (probably using Web.config) to use the document_root as the default folder for the site (making the root invisible) so i can call mydomain.tld/ instead of mydomain.tld/document_root/

I have used:

<defaultDocument>
  <files>
    <clear />
    <add value="document_root/index.php" />
  </files>
</defaultDocument>

Which works fine but it accesses only the index.php and cant find any files like /document_root/css/default.css (the relative address is css/default.css)

like image 900
Ragnar Avatar asked Oct 25 '25 03:10

Ragnar


1 Answers

There are 2 ways to do this. The easy route is to use the URL Rewriting module included in IIS7. An example to redirect requests to the Public folder (and disallow direct access to that folder) :

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="blockAccessToPublic" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{URL}" pattern="/public/*" />
                </conditions>
                <action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
            </rule>
            <rule name="RewriteRequestsToPublic" stopProcessing="true">
                <match url="^(.*)$" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                </conditions>
                <action type="Rewrite" url="public/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

The other way is to change the IIS settings once your PHP application is deployed. To do that you need to override the OnStart method of your web role, but I think the first solution will suit your needs.

like image 92
pierrecouzy Avatar answered Oct 26 '25 17:10

pierrecouzy