Announcement

Collapse
No announcement yet.

redirect directory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • redirect directory

    is there any way i can let users type in an url for their homepage like: http://www.myasl.net/$username, but not actually create the dir $username, instead have a script that redirects the user to something like: http://myasl.net/script.php?user=$username

    any help greatly appreciated!

  • #2
    c'mon

    Yahoo Profiles do it, so i know it can be done, but how?

    c'mon ppl, someone out there must know the answer!

    Comment


    • #3
      I think you can do it with an .htaccess file (put it in your web root):

      ErrorDocument 404 /script.php

      Make the script redirect using $PATH_INFO as the directory requested.

      Comment


      • #4
        which variable?

        I have done as you said, but I'm not sure on which variable to use to figure out where the visitor wants to go.
        heres my code so far:
        PHP Code:
        $redirect $PATH_INFO;
        echo 
        $redirect
        the $redirect variable is always empty, so i tried using REQUEST_URI, but that just showed the url to the redirect script.
        I also tried HTTP_REFERER, but that came out empty also.

        which variable should I use?
        and then how would I process the variable to get just the end directory name, eg. http://domain.com/bob, then make the variable $dir = "bob".

        any ideas?

        Comment


        • #5
          Hmm, try putting phpinfo() in the script, which will list all the server's environment variables (as well as a bunch of other goodies). One of those should contain what you want.

          Comment


          • #6
            still no luck

            I tried using all the different predefined variables that may hold the requested url data, but none work.
            I think its because the .htaccess file redirects to my redirect.php script, so the REQUESTED_URI variable is showing the path to the redirect.php script.
            Is there any way to get around this, I'm sure there would be, so please help me out.
            Thanx.

            Comment


            • #7
              Did you try $QUERY_STRING? I am using it in one of my scripts. However, I am calling the script name too. ie...http://www.mysite.com/script.php?variable

              Just a thought.

              Chris

              Comment


              • #8
                did anyone bother to read docs on Apache?

                I'm no expert (or even close), but this *looks* like it may be what you want... http://httpd.apache.org/docs-2.0/misc/rewriteguide.html
                [look for "Redirect Failing URLs To Other Webserver" about a third of the way down]
                Code:
                RewriteEngine on
                RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
                RewriteRule   ^(.+)                             http://your_domain.com/script.php?user=$1
                Good Luck,

                Comment


                • #9
                  experienced?

                  any experienced programmers out there got any idea?
                  coz I really need to get this done pronto, but I've hit a rut.
                  anyone else got some input?
                  could i get my host to set a php script as the 404 error by default?

                  Comment


                  • #10
                    Did neither of our suggestions work? Max Albert's idea was the best of the two.

                    Chris

                    Comment


                    • #11
                      how?

                      I dont know how to get maxalberts idea to work, I tried just copying his code straight into the .htaccess file located in the base directory, but it didnt seem to work.
                      Is that the code I need to use exactly? or what do i need to change?

                      Comment


                      • #12
                        Code:
                        RewriteEngine on
                        RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
                        RewriteRule   ^(.+)                             http://your_domain.com/script.php?user=$1
                        the /your/docroot/ needs changed to whatever your document root is. This is the physical path on the machine to where your files are. It will look something like /home/myasl/

                        also, the http://your_domain.com/script.php?user=1 needs chagned to to wherever you want to sent people. I'm guessing you want http://myasl.net/script.php?user=$1

                        Comment


                        • #13
                          Now this is crazy old but I do have a script that will show users profiles just curious if it was set up the same way as it was talked about back in 01 (using script.php?) how would the file look?

                          Thanks.

                          Comment

                          Related Topics

                          Collapse

                          Working...
                          X