How to add "www." to a web site with web.config?

0

I do not have much knowledge in regular expressions and I'm trying to identify if the user entered the site before entering the website before the site name.

If it has not typed, I have to add it. But I'm having a bit of trouble doing this in asp web config. I tried something like this:

<rule name="teste">
  <match url="^([^w]\w*)">;
  <action type="Rewrite" url="www.{R:1}">
</rule>
    
asked by anonymous 16.08.2016 / 16:57

2 answers

2

Following the logic of this other answer I did Remove "www" from the domain by doing 301 redirect , the difference is which has to "swap" action type="Redirect" by add input :

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Adiciona prefixo WWW">
                <match url="(.*)" ignoreCase="true" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^MEUDOMINIO\.com" />
                </conditions>
                <action type="Redirect" url="http://www.MEUDOMINIO.com/{R:1}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
    
16.08.2016 / 17:19
1

I also managed to do it in a similar way. Here's the example for who needs it:

<rule name="Add WWW" stopProcessing="true">
  <match url="^(.*)$" />
  <conditions>
     <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)$" />
  </conditions>
  <action type="Redirect" url="http://www.{C:0}{PATH_INFO}" redirectType="Permanent" />
</rule>
    
16.08.2016 / 18:23