• URL Redirection

    Author
    Topic
    #427822

    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 http://www.freshties.com/username should redirect the user to http://www.freshties.com/myCommunity.php?action=blog&user=username 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

    Viewing 0 reply threads
    Author
    Replies
    • #992675

      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 http://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! sailing

      • #992766

        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.

      • #992768

        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.

        • #992846

          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, which creates a dynamic sitemap for your site, based on the Navigation Structure that FrontPage uses.

          • #992848

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

    Viewing 0 reply threads
    Reply To: URL Redirection

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: