Web Config IIS

Léo Colombaro edited this page Apr 14, 2014 · 9 revisions

What your web.config file for IIS should look like

Make a web.config file

If your YOURLS installation is on a IIS machine you have to create a web.config file. It's simple.

Case: YOURLS installed on root

If YOURLS root URL is http://yoursite/, the web.config file in the root directory must be like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
        <rewrite>
            <rules>
                <rule name="YOURLS" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions>
                        <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="/yourls-loader.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Case: YOURLS installed in subdirectory

If YOURLS root URL is http://yoursite/somedir/, the web.config file in this subdirectory must be like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
        <rewrite>
            <rules>
                <rule name="YOURLS" stopProcessing="true">
                    <match url="^somedir/(.*)$" ignoreCase="false" />
                    <conditions>
                        <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="/somedir/yourls-loader.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Bonus: Force non-WWW

Add this before the YOURLS rule block in your web.config file, replacing yourls.org with your own domain

<rule name="YOURLS www" stopProcessing="true">
    <match url="^(.*)$" ignoreCase="false" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www\.yourls\.org$" />
    </conditions>
    <action type="Redirect" url="http://yourls.org/{R:1}" redirectType="Permanent" />
</rule>

This directive MAY or MAY NOT work on your host (ie http://sho.rt/stuff might work fine and http://www.sho.rt/stuff might not). If it doesn't work, simply stick to one domain, either with or without www. There is no real support for both www and non-www domain setup.

(This is unlikely to get improved, to be honest. I don't get why people insist on adding 4 extra characters (www.) to their URL shortener...)

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.