redirect url site with relative path

lawrence whittemore asked on March 30, 2017 17:40

Is it possible to have the site url if entered without www add the www but keep the relative path and not just redirect to a single page.

so if someone types mysite/about-us.aspx

the site will redirect to www.mysite/about-us.aspx

Recent Answers


Brenden Kehren answered on March 30, 2017 17:59

You can accomplish this with making sure 2 things are done:

  • main domain of the site should be www.domain.com. Add the alias for domain.com
  • in the site settings you can specify this in the URLs & SEO section and set the Process domain prefix to "always use domain with www prefix".

These two changes will ensure you will always have a www in front of your domain.

1 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on March 30, 2017 18:01

Or you can add the following section to your web.config file:

<rewrite>
    <rules>
        <rule name="301 Redirect to www and to main domain">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTP_HOST}" matchType="Pattern" pattern="^site.com$" ignoreCase="true" negate="false" />
            </conditions>
            <action type="Redirect" url="http://www.site.com/{R:1}" redirectType="Permanent" />
        </rule>
</rules>

0 votesVote for this answer Mark as a Correct answer

lawrence whittemore answered on March 30, 2017 19:32

I can't find the "Process domain prefix" in the settings. The site is in kentico 6.

I also tried the web config edit but it just crashes the site.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 30, 2017 19:39

It's in v7 so I can only assume it was in v6. But if you look specifically in Settings>URLs & SEO>SEO - URLs it would be in that area. OR select the top node of Settings and search for Domain. It should show that way as well.

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on March 30, 2017 20:06

Do you have URL Rewrite module? And there is a system.webServer section in web.config where you should create the rules (more info about rules here Creating Rewrite Rules for the URL Rewrite Module), if it doesn't exist, just add it, so your web.config file will have this format:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
 <system.webServer>
    ...
    <rewrite>
      <!-- your rules -->
    </rewrite>
    ...
 </system.webServer>
 ...
</configuration>

But it's better to use Kentico settings which wre mentioned by Brenden

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.