web.config file location and redirect not working
# help-with-other
j
Our website is ready to go live, but I think I may have accidently moved web.config file to a different folder. Should the web.config file be located in the wwwroot folder? I added the following rewrite in the web.config file, it did not redirect to my custom hostname. I replaced https://www.example.com to my hostname. The hostname starts with account not www.
Copy code
<rewrite>
                <rules>
                    <rule name="Redirect umbraco.io to primary hostname" stopProcessing="true">
                        <match url=".*" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="\.umbraco\.io$" />
                            <add input="{HTTP_HOST}" pattern="^(dev-|stage-)(.*)?\.umbraco\.io$" ignoreCase="true" negate="true" />
                            <add input="{REQUEST_URI}" pattern="^/umbraco" ignoreCase="true" negate="true" />
                            <add input="{REQUEST_URI}" pattern="^/App_Plugins" ignoreCase="true" negate="true" />
                            <add input="{REQUEST_URI}" pattern="^/sb" negate="true" />
                            <!-- Don't redirect Smidge Bundle -->
                            <add input="{HTTP_COOKIE}" pattern="^(.+; )?UMB_UCONTEXT=([^;]*)(;.+)?$" negate="true" />
                            <!-- Ensure preview can render -->
                            <add input="{HTTP_HOST}" pattern="^localhost(:[0-9]+)?$" negate="true" />
                        </conditions>
                        <action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
                    </rule>
                </rules>
            </rewrite>
r
If it’s on Umbraco Cloud it’s expected to be in the root folder deployed, meaning in the web projects root which defaults to
src/UmbracoProject
j
I moved to src/UmbracoProject but it didn't redirect to account.something.com
I tried www.something.com but still won't redirect...
r
Is that where your web project is located (The one referenced in the .umbraco file)? I don’t remember exactly, but I think is should work if it’s in
web.config
. You can always check kudu to see if
web.config
in the deployed folder (wwwroot, not to be confused with the projects wwwroot folder) has the correct rules https://docs.umbraco.com/umbraco-cloud/set-up/power-tools
j
So web.config and .umbraco files they should be located in the same folder?
Also, I'm always confused why there is another wwwroot inside the wwwroot with kudu.
r
No sorry,
web.config
should be in the folder referenced in the
.umbraco
file which defaults to
src/UmbracoProject
, so if you haven’t changed that it should work placing it in
src/UmbracoProject
, if it doesn’t contact support and they’ll help you (or I can test it out tomorrow and come back to you)
Yeah, for some reason .NET (core) dropped the
bin
folder and added all files to the root and public files to
wwwroot
, azure already used
wwwroot
as the root folder for the web project, and the nested one is by default for public files e.g. files that can be downloaded through the browser
j
make sense. I think the screenshow above is correct location for web.config file.
Let me try again. I would expect something.umbraco.io (default hostname from umbraco) should just redirect to account.something.com (my hostname)...
If I want to check web.config in the deployed folder in kudu. Should I check wwwroot/wwwroot (nested) or just wwwroot?
Just checked I do have wwwroot/web.config file but redirect still not working...
r
Should be
wwwroot/web.config
(not the nested folder), if the rules aren’t there, then something’s wrong with the deployment/location of
web.config
, if they’re there then it’s the rules.
j
the rule is there.
I'm wondering if this only work with www. prefix
One approach for this is to add a new rewrite rule to the section in the web.config file. For example, the following rule will redirect all requests for the project example.euwest01.umbraco.io URL to the example.com URL (using HTTPS and including the www. prefix) and respond with a permanent redirect status.
r
I guess it depends on the rule (currently on my phone so it’s kinda hard to see code snippets, however at a glance they do look correct), I can test it tomorrow to see if there’s anything missing
j
Thank you! I appreciate it! Just let me know!
Looks like it works today. Maybe just need few hours to load the settings into the IIS.
81 Views