Submit a Ticket
Support Center » Knowledgebase » URL Redirection for Windows plans (web.config)

URL Redirection for Windows plans (web.config)

If you wish to redirect your website to another URL via code, please follow the steps below:

With ASP code directly in the "default" webpage:


1. Open the web-page via File Manager or a FTP client.


2. Add the following code to your web-page, replacing www.domain.com with the new URL where you wish to redirect to:


<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com"
%>

PS. Change domain.com to the URL to which you wish to re-direct the website.



With ASP.NET code directly in the "default" webpage:


1. Open the web-page via File Manager or a FTP client.


2. Add the following code to your web-page, replacing www.domain.com with the new URL where you wish to redirect to:


<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.domain.com");
}
</script>

PS. Change domain.com to the URL to which you wish to re-direct the website.



Using WEB.CONFIG 301 redirect:


This example, will redirect important pages of your site that have .htm extensions and you want the new location to be its own directory (IE. http://domain.com/services.htm will change to http://domain.com/services/).

1. Edit the web.config either via File Manager or FTP client.


2. Add the code below:


<configuration>
  <location path="services.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
  <location path="products.htm">
    <system.webServer>
      <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>

PS. You may add as many location paths as necessary.



This example will redirect an entire directory to a new location. To do that proceed with the same steps as in the first example, only change the code with the one below:

<httpRedirect enabled="true" destination="http://domain.com/newdir" httpResponseStatus="Permanent" />


PS. Change http://domain.com/newdir with the new URL to which you wish to re-direct. 





Redirecting non-www to www using WEB.CONFIG:


Generally redirection of non-www to www is made for search engine optimization purposes. This redirection uses the URL Rewrite module which is installed on all of our Shared Windows Servers.

1. Edit the web.config either via File Manager or FTP client.


2. Add the code below:


<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"
               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
 
PS. Change domain.com to the URL to which you wish to re-direct the website.

 This answer was helpful  This answer was not helpful
 Back