Results 1 to 6 of 6

Thread: URL Redirection

  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Porthcawl, Mid Glamorgan, Wales
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    URL Redirection

    I want to set up a new service for customers of my web sites and the functionality I want to give them is this:

    Entering a URL of <font color=red>www.freshties.com/username </font color=red> should redirect the user to <font color=448800>http://www.freshties.com/myCommunity...&user=username </font color=448800> where username in both URLs is the same.

    My server is running Windows 2003 Web Edition and IIS6, PHP5

    Any ideas how to achieve what I want would be gratefully received.

    Happy New Year to ALL

  2. #2
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: URL Redirection

    You can do this with an ASP page.

    Function RedirectForUserAccount()
    dim strUserName
    dim intPos
    strUserName=request.servervariables("QUERY_STRING" )
    intPos=instrrev(strUserName,"/")
    if intPos>0 then
    strUserName=mid(strUserName,intPos+1)
    end if
    If CheckIfValidUser(strUserName) then
    response.redirect ""/myCommunity.php?action=blog&user=" & strUserName
    End if
    End Function

    Function CheckIfValidUser(strUserName)
    'Check your user database if it's a valid user account
    'Return this function based on that check
    End Function

    Put the first function in an .asp page, create the section function to validate whether or not 'strUserName' is a valid account name or not.

    Now, the key is to trigger that page. You need to setup that page to get page not found errors. Go into the properties of your website, and go to the Custom Errors Tab (I use IIS 5.0, so things may be slightly different with your version, but probably not much. Find HTTP Error 404. Edit the properties, set Message Type to URL, and URL: to /yournewasppage.asp.

    Now, when someone goes to www.freshties.com/Drew , if Drew is not a valid directory or page on your site, it will redirect them to your new custom 'page not found' page, which then uses ASP in the first function to send 'Drew' to the second function (which you'd have check your database of users, to determine if 'Drew' is a valid account name'), and if it's a valid account, it redirects like you want. If not, you'd want to have a 'page not found' error come up.

    Hope that helps! <img src=/S/sailing.gif border=0 alt=sailing width=25 height=25>

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Porthcawl, Mid Glamorgan, Wales
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: URL Redirection

    Thanks Drew, will check this out later this week. I got so caught up in using PHP it didnt occur to me to use ASP... doh.

    I'll let you know how I got on.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Porthcawl, Mid Glamorgan, Wales
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: URL Redirection

    BTW this has 'killed 2 birds' so to speak. I was just getting to set up my custom error pages.

    I can also do this with PHP anyway so thats even better, from my point of view.

  5. #5
    4 Star Lounger
    Join Date
    Aug 2002
    Location
    Dallas, Texas, USA
    Posts
    594
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: URL Redirection

    No problem. You should be able to do the same thing with a php page. I'm just not sure what you need to do there. Only PHP I have written was for this <post#=222317>post 222317</post#>, which creates a dynamic sitemap for your site, based on the Navigation Structure that FrontPage uses.

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Porthcawl, Mid Glamorgan, Wales
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: URL Redirection

    Our whole site is built using php so it wont be a problem. Thanks again. Must remember to look closer to home next time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •