Link to home
Start Free TrialLog in
Avatar of jdr0606
jdr0606Flag for United States of America

asked on

Website URL redirection

I'm using IIS for a website but I have a redirection issue

If i enter the URL www.site.com/buyproducts it takes me to www.site.com/buyproducts however if I don't enter the www and just site.com/buyproducts it takes me to www.site.com.

Where would change the settings so that it will take me to www.site/com/buyproducts or site.com/buyproducts depending on which I enter?

Thanks
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

To redirect yourdomain.com to www.yourdomain.com, edit your web.config file and add the below segment under the <system.webserver> section. Ensure you modify the words “yourdomain.com” with your appropriate domain name.

<rewrite>
      <rules>
            <rule name="Redirect http://yourdomain.com to http://www.yourdomain.com HTTP" patternSyntax="ECMAScript" stopProcessing="true">
          <match url=".*"></match>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^yourdomain.com$"></add>
            <add input="{HTTPS}" pattern="off"></add>
          </conditions>
          <action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
        </rule>
      </rules>
    </rewrite>

Open in new window

Avatar of jdr0606

ASKER

I'm not sure I was clear on my original email

What I want to happen is:

If I enter www.site.com/buyproducts I want it to go to www.site.com/buyproducts

but if I enter site.com/buyproducts I want it to go to site.com/buyproducts

Thanks
As per Google or other search engine, you can use only one way of URL, It can be with www or without www.

If you using both Google can penalizes the website as duplicate content.

So first you must be finalize which domain you want to carry on.
Avatar of jdr0606

ASKER

Thanks for the info Alex

So let me look at it differently

If I enter www.site.com/buyproducts I want it to go to www.site.com/buyproducts

but if I enter site.com/buyproducts I want it to go to www.site.com/buyproducts
Perfect.

Now you can follow my first comment to resolve the issue.

Need any help feel free to contact.

Alex
Avatar of jdr0606

ASKER

Alex, as you can probably tell, i'm not very proficient with web.config or rewrite syntax.  I tried adding the code you suggested but it then generated a 500 error.  I likely need to replace rather than add to my existing rewrite but not sure where.

Here is what I have now under the rewrite section

        <rewrite>
            <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^morecatalogs$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="morecatalogs.aspx" />
                </rule>
                <rule name="morecatalogs with slash">
                    <match url="morecatalogs/" />
                    <action type="Rewrite" url="morecatalogs.aspx" />
                </rule>
            </rules>
        </rewrite>
ASKER CERTIFIED SOLUTION
Avatar of Alex Smith
Alex Smith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdr0606

ASKER

This is what I entered, however when I enter kele.com/smartbuy it redirects to www.kele.com

Do I need to look at something in IIS as well?

       <rewrite>
            <rules>
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^morecatalogs$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="morecatalogs.aspx" />
                </rule>
                <rule name="morecatalogs with slash">
                    <match url="morecatalogs/" />
                    <action type="Rewrite" url="morecatalogs.aspx" />
                </rule>
<!-- Entered this URL 2016-10-06 -->
            <rule name="Redirect http://kele.com to http://www.kele.com HTTP" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*"></match>
                <conditions>
                        <add input="{HTTP_HOST}" pattern="^yourdomain.com$"></add>
                        <add input="{HTTPS}" pattern="off"></add>
                </conditions>
          <action type="Redirect" url="http://www.kele.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
              </rule>

            </rules>
        </rewrite>
Hi,

If you want to redirect the single page than you can also place the below given meta tag to your kele.com/smartbuy page header.

<meta http-equiv="refresh" content="01; ,URL=http://www.kele.com">

Please let me know have any issue.

Alex