Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2/PHP/IIS7 - URL Rewrite and File Permissions (Pretty URL issue)

I have a web.config file with the following text, although not relevant to my problem...

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Pretty URL">
                    <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" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Normally when I develop on my Windows machine the folder with my PHP source has permissions for all authenticated users and pretty URLs in my Yii2 website works without any issues.

Now, my next project requires me to deploy on a Windows machine where non-admin users will also use and I tested deploying a Yii2 website to a folder that gives IUSR user the ability to List, Read, & Execute files.

The website works, but the pretty url does not.

If I copy the folder contents to another location with regular authenticated user and SYSTEM permissions, it works as expected.

I think I am missing some permissions that will enable pretty URL to work properly with IIS7 URL Rewrite module, but not sure what.

like image 957
Shahid Thaika Avatar asked Aug 08 '18 07:08

Shahid Thaika


People also ask

What is the Microsoft url rewrite module for IIS 7?

The Microsoft® URL Rewrite Module for Internet Information Services 7 (IIS 7) and above provides flexible rules-based rewrite engine that can be used to perform broad spectrum of URL manipulation tasks, including, but not limited to: Enabling user-friendly and search engine-friendly URLs with dynamic Web applications.

How do I match content within a URL Rewrite response?

Set the ‘Matching Scope’ to ‘Response’ in the dropdown, make sure that all the items within the ‘Match Content Within’ dropdown are deselected – this will mean URL Rewrite will scan the entire response not just specific tags. Select ‘Matches the Pattern’ in the ‘Content’ dropdown and ‘Regular Expressions’ in the ‘Using’ dropdown.

Can IIS use URL Rewrite as a reverse proxy?

Sep 10 2019 03:06 AM This is the third part of the article series dealing with IIS using URL rewrite as a reverse proxy for real world apps. Check out part 1 and part 2 before reading on.

How to expose the rewritten url in a rewrite rule?

For example, if a substitution URL in a rewrite rule is " /folder1/folder2 ", and these folders exist on file system and have default document configured, then DefaultDocument module redirects a Web client to " /folder1/folder2/ ", thus exposing the rewritten URL.


1 Answers

In Linux it's quite common that servers run as special user.
I apply this habit even in Windows and it's easy to configure access then for the server. User accounts shouldn't matter then related to the server.
Ownership of all files in the web-directory has to be then the user of the web-server, i.e. "IUSR".
The user as which the server is running has to be adjusted in IIS configuration if it differs from "IUSR" which is the default IIS-user.

Only for file-access related to editing some adjustments might be required for all files but if the server is running as a user it's also clearer that file-access for editing and for server-access are two different purposes. So you even can adjust edit-access to limited files for users, while the server has full access to all files. Giving different access-rights to different users or usergroups is also no problem.

For more details about the default IIS-user you can read Understanding Built-In User and Group Accounts in IIS 7

like image 194
David Avatar answered Oct 07 '22 02:10

David