Print Page | Close Window

Non-www redirect to www

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums
Forum Description: Support forum for Web Wiz Forums application.
URL: https://forums.webwiz.net/forum_posts.asp?TID=27233
Printed Date: 02 April 2026 at 7:08pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Non-www redirect to www
Posted By: MortiOli
Subject: Non-www redirect to www
Date Posted: 08 April 2009 at 7:27pm
Anyone know how I can alter the forum so it redirects people to the www. version of the site / page?

For example;

http://myforum.com/new_topic_form.asp?FID=24 redirects to http://www.myforum.com/new_topic_form.asp?FID=24

I'd need to do it through ASP, as it's a Windows server.

Cheers!



Replies:
Posted By: WebWiz-Bruce
Date Posted: 09 April 2009 at 10:16am
I would do this at IIS level on the web sever rather than with ASP.

Setup a new website in IIS for myforum.com without the www. part and then have it redirect to the www.myforum.com website. If you don't select the option of an 'exact desitination' then it will also still include the path and file names when it redirects.

-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: kiklop
Date Posted: 09 April 2009 at 2:27pm
here is what i'm using (not my code so i pasted code and comments). Hope it helps

<%
'This code will redirect any asp page to the www version
'This code is provided as-is with no guarantee or warranty
'It is provided for free distribution as long as these comments
'are left in place.
'Designed by www.jlh-design.com 2006
'An entire site can be redirected by using and include like:
'at the top of each page before the first <HEAD> Tag

Dim Domain_Name, theURL, QUERY_STRING, HTTP_PATH,TEMP_NUM
'Get domain that the page is on
Domain_Name = lcase(request.ServerVariables("HTTP_HOST"))
'Check if URL is the www version
if left(Domain_Name, 3) <> "www" Then
    HTTP_PATH = request.ServerVariables("PATH_INFO")
'Check if page is default.asp if so, redirect to "/".  If other index page is used, such
'as index.asp the numbers in the right and len statement need to be changed, as well
'as the IF statment to indicate the index page.
        If right(HTTP_PATH, 12) = "/default.asp" Then
            TEMP_NUM = len(HTTP_PATH)-11
            HTTP_PATH = left(HTTP_PATH,TEMP_NUM)
        End If
' Sets the new URL settings with correct page
    QUERY_STRING = request.ServerVariables("QUERY_STRING")
    theURL = "http://www." & Domain_Name & HTTP_PATH
'This section passes on the query string variables
        if len(QUERY_STRING) > 0 Then
            theURL = theURL & "?" & QUERY_STRING
        end if
' Send 301 response and new location
    Response.Clear
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", theURL
    Response.Flush
    Response.End
end if
%>


-------------
http://www.dyxum.com" rel="nofollow - dyxum.com



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net