Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Non-www redirect to www
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Non-www redirect to www

 Post Reply Post Reply
Author
MortiOli View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 May 2002
Location: United Kingdom
Status: Offline
Points: 514
Post Options Post Options   Thanks (0) Thanks(0)   Quote MortiOli Quote  Post ReplyReply Direct Link To This Post Topic: Non-www redirect to www
    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!
Back to Top
WebWiz-Bruce View Drop Down
Admin Group
Admin Group
Avatar
Web Wiz Developer

Joined: 03 September 2001
Location: Bournemouth
Status: Offline
Points: 9844
Post Options Post Options   Thanks (0) Thanks(0)   Quote WebWiz-Bruce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
kiklop View Drop Down
Groupie
Groupie


Joined: 14 July 2005
Status: Offline
Points: 137
Post Options Post Options   Thanks (0) Thanks(0)   Quote kiklop Quote  Post ReplyReply Direct Link To This Post 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
%>
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.