问题
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)
回答1:
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.
回答2:
Modify the BASIC SETTINGS and WEBSITE BINDINGS. If you only have one website, you will probably just want to edit the BASIC SETTINCGS for the DEFAULT WEBSITE:
- Open IIS Manager
- Click on Default Web Site
- Under Actions (right hand side), select Basic Settings
- Edit Physical Location.
If you are testing several websites on one development machine (with different "DOCUMENT_ROOT" folders), right-click on each website in the list, Edit Bindings, and set the various websites to run under different Port Numbers. Then, you can access the various websites using (for example): http-colon-slash-slash localhost:81
回答3:
I am coming at this from the other angle (knowing little PHP but IIS and Azure well). I don't know why your project is structured the way it is, so I'll just assume it has to be that way for some reason. I would just like to point out that in my experience it's a little atypical to have a subfolder that you want to work as the root and not just have it at the root.
Regardless, the techniques I would look at are called Rewriting or Routing, which lets you change from standard the way that URLs are parsed and passed to executing pages. Stackoverflow has lots of posts about it that you might like to trawl, here's a good one IIS URL Rewriting vs URL Routing which gives an answer as to two different types of routing and where to use which.
You can do it in web.config, and it should let you achieve what you want.
来源:https://stackoverflow.com/questions/5796085/iis-document-root-in-subfolder