Server Fault Asked by Appleoddity on December 16, 2021
I want: http://somesite.com to redirect to http://somesite.com/subfolder
Seems like a pretty simple request. I’ve followed the sources online, and they all indicate I should use ^$
for the regex pattern. I’ve also added an HTTP to HTTPS redirect, and it works fine. I’ve also tried disabling that rule just to make sure it wasn’t interfering. This is running on IIS 10 / Server 2016.
My web.config looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect root to NmConsole" stopProcessing="true">
<match url="^$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="/subfolder" appendQueryString="true" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Requests to the root domain do not redirect. Why isn’t it working?
Maybe HTTP Redirect is more appropriate here, though the feature is not enabled by default.
For Windows Server, go through the add features and roles wizard and enable HTTP Redirection
under Server Roles > Web Server (IIS) > Common HTTP Features
For Windows desktop, go through appwiz.cpl
and Turn Windows Features On or Off
instead.
Once that's enabled, you'll add:
<system.webServer>
<httpRedirect enabled="true" destination="http://somesite.com/subfolder" />
</system.webServer>
to your web.config
file and you should be in business. You can read more about it at Microsoft's documentation
Answered by sippybear on December 16, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP