Mobile app version of vmapp.org
Login or Join
Mendez628

: How do I use IIS7 rewrite to redirect requests for (HTTP or HTTPS):// (www or no-www) .domainaliases.ext to HTTPS://maindomain.ext I have multiple domain names assigned to the same site and I

@Mendez628

Posted in: #Iis7 #Redirects #UrlRewriting

I have multiple domain names assigned to the same site and I want all possible access combinations redirected to one domain. In other words whether the visitor uses domainalias.ext or www.domainalias.ext or www.domainalias3.ext or domainalias4.ext or any other combination, including maindomain.ext, www.maindomain.ext, and www.maindomain.ext they are all redirected to maindomain.ext
I currently use the following code to partially achieve my objectives:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>
<system.webServer>
<rewrite>
<rules>

<rule name="Redirect to MAINDOMAIN.EXT stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^MAINDOMAIN.EXT$" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://MAINDOMAIN.EXT/{R:1}" />
</rule>

<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>


...but it fails to work in all instances. It does not redirect to maindomain.ext when user inputs (www.)domainalias.ext
So my question is, are there any programmers here familiar with IIS7 ReWrite that can help me modify my existing code to cover all possibilities and reroute all my domain aliases, loaded by themselves or using www in front, in HTTP or HTTPS mode, to my main domain in HTTPS format???

The logic would be: if entire URL does NOT start with maindomain.ext then REDIRECT to maindomain.ext/(plus_whatever_else_that_followed).
Thank you very much for your attention and any help would be appreciated.

NOTE TO MODS: If my question is not in the correct format, please edit or advise. Thanks in advance.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Mendez628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Steve110

I believe this is a basic example of what you need to do:

<rewrite>
<rules>
<rule name="Redirect to maindomain.ext with SSL" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^maindomain.ext$" negate="true" />
</conditions>
<action type="Redirect" url="https://maindomain.ext" />
</rule>
</rules>
</rewrite>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme