MarkR - thanks for posting, I'm not sure I follow the 404not found page idea. How does the 404 page check if the user exists? If it can check using the name typed in, then it means that name is stored as a variable somewhere, if that's the case, all I need to know is how to access that variable and I can use it to query my database.

I've never worked with 404 pages before so bare with me as a newbie.

As for apache, I'm trying to install it now, the website said something about having to have vb 6 installed, I hope that's not the case, but I'm gonna give it a try.

    mcslug: The 404 is a good technique. You look at the environment variables and find the one that tells you the URL. Then you use a regexp to find the string that follows www.yourdomain.com. Once you have that string, you know the username and you can look that up in a database and display their page.

    But I have another technique that I prefer. I set up a wildcard in my DNS so that *.mydomain.com all resolves to the same IP. Then I make my index.php page check the environment variables with the URL to find the domain name and see what preceeds mydomain.com. And that's their username. That way, When "bob" registers for an account, his URL is: http://bob.mydomain.com

    This way, you're not piggy backing on the 404 error page function which you might really want to use for 404 error pages!

      etully - thanks for the suggestion!

      that definitely sounds like what I would want to do, but I have no idea how to go about doing so 🙂 I'll try and look it up some more

      I have a new problem though, installing php5 and apache 2.2 on windows srvr03. For whatever reason when I put the line in the httpd.conf file:
      LoadModule php5_module "C:/php/php5apache.dll"
      and then I restart apache it says, "could not find module"

      I have looked it up and everyone says put that line in and it works, except it doesn't. Grrr

      anyway, if I ever get apache up I'll look into the DNS usage, I just don't understand how it knows to use the * entry as a variable, or where it stores it, or how I reference it using php.

        For installing PHP on an Apache 2 webserver, simply follow the instructions on this man page: [man]install.windows.apache2[/man] (NOTE: I'd recommend following the ISAPI module instructions, NOT the CGI binary, as it appears you're trying to do).

        EDIT: Don't forget to read the entire manual page! It says to follow the "manual installation steps" after downloading PHP and BEFORE integrating with Apache. These instructions can be found on this man page: [man]install.windows.manual[/man] .

          bradgrafelman - thanks, it turns out the latest release of apache 2.2.2 is not working properly with php

          Once I switched to 2.0.48 it works just fine. Thanks for the reference!
          Now I'm going to try and tackle etully's idea, and look up more info, any other information is appreciated, thanks for all your help so far everyone!

            mcslug:
            1. set up a DNS record for .yourdomain.com pointing to your IP address
            2. set up Apache so that
            .yourdomain.com goes to your web directory

            (That's not normal. Normally, you have WWW.yourdomain.com going to one directory and BOB.yourdomain.com going to another directory and TONY.yourdomain.com going to a thrid directory. In your case, you're going to point [everything].yourdomain.com to the same directory).

            1. Write an index.php file in your web directory that determines which URL was used to arrive at that directory like this:

            $domain = $_SERVER['SERVER_NAME'];
            ereg("(.+).yourdomain.com",$domain,$regs);
            $username = $regs[1];

            Now that you know $username, you can do whatever you want to include the content that belongs to that user.

            I hope that helps.

              thanks again etully, I'm working on it so far. Here's what I'm assuming all of this means (I'm a noob with some of this so bare with my ignorance if you can)

              I set up dns on my srvr03 box, and added a forward look up zone alias for *.mysite.com (not sure if this is what you mean by setting up a new dns record.) but when I ping blah.mysite.com it says unresolved. Is this something that can be done with windows? or do I HAVE to use linux/unix?

              In my httpd config file for apache I'm putting under the alias section:
              Alias *.mysite.com "C:/Program Files/ Apache Group/Apache2/htfiles"
              I'm assuming this is what I do to allow apache to forward requests for blah.mysite.com to go to the index file I set up in the htfiles folder?

              I guess my questions are, a, is this right, and b, can it be done with windows?

                mcslug:
                I don't use Windows so I'm not going to be able to help you with syntax either for DNS configs or Apache configs.

                For the DNS, you are trying to set up a wildcard "A" record in your zone - not a wildcard zone file (if there is such a thing). Your zone file is for "mysite.com". A normal "A" record (which is inside a zone file) converts a name like "www.mysite.com" to an IP like 1.2.3.4. In your case, you want the "A" record to convert *.mysite.com to your IP address.

                For Apache, you have the general idea. Instead of making "www.mysite.com" point to "C:/Program Files/ Apache Group/Apache2/htfiles" You want *.mysite.com to point to that directory. This way, whatever subdomain is typed in brings you to that directory. You are on the right track. I just can't help you with Windows sysadmin.

                  etully-

                  well windows is a bust, but then, so is apache. The .mysite.com redirection doesn't work either in windows dns or in apache because it views as a regular character and not a "wildcard" character. So now I'm wondering if linux is just going to do the exact same thing?

                    I've been doing this on Linux for the last five years both in DNS and Apache. You should be able to do it on Windows - you might just need a good manual or a good sysadmin. Of course, that would be true of Linux too - a good manual or a good sysadmin.

                    I know that this is a frustration for you. All I can tell you is that this is pretty straight forward - there's no magic or anything. You're setting up an "A" record for and you're setting up a <virthost> in Apache for .mysite.com. It's a little out of the mainstream but it's not that far out of the mainstream. I suspect that a few Google searches might shed some light. Maybe there's a good forum for Windows sysadmin?

                      etully -
                      what environment are you running it on, what version of linux/unix, what version of apache?

                      To give some back ground, I'm running apache 2.0.48 on srvr03. I setup the "A" record for dns as *.mysite.com and also set up the virtual host in apache

                      I know it's set up right, the problem is as I said before, if I ping mcslug.mysite.com I get no reply, but if I ping .mysite.com it comes back, so it's taking .mysite.com as literal characters and not a wildcard character. I've also tried this setup with the same version of apache and fedora core 5, but since apache ALSO takes * as a literal character, it still doesn't use it as a wild card. I'm thinking there's another way to do this that I just don't know of.

                      Thanks for the help, I'll keep plugging away!

                        I don't know if you have the ability to manually edit the DNS zone, but for njoe.com, I have two entries setup as follows:

                        @ IN A 62.214.98.14
                        * IN A 62.214.98.14

                        This allows for any subdomain, OR no subdomain, to properly point to the webserver.

                        If you can't edit the actual DNS zone file, you might need to contact your host, who knows.

                          mcslug:

                          bradgrafelman is right, this has to do with configuring your DNS. I've used this technique for 5-6 years on lots of different versions of Linux and Apache. (You are having a DNS problem, not an Apache problem). This will work on all versions of Unix because you edit your zone file as a text file, not a GUI tool that edits your zone file (and appears to be getting it wrong). You could contact your host - or Google - for help and see if they can suggest a way to add a wildcard record to your zone file. (I just don't know how to do it in Windows.)

                          Alternately, you could host your DNS at a more friendly place. I use dnsmadeeasy.com even though I host my web sites at various hosting companies. Even though web hosting companies typically include DNS service with their web hosting packages, you don't need to use their services if you don't want to (for example, if you are having trouble adding a wildcard to your zone file).

                          I once had a web hosting company tell me that they wanted $10 per DNS change. I simply went to my registrar and changed the name servers to dnsmadeeasy.com ($20 per year) and the web hosting company doesn't know that I do my DNS service elsewhere.

                            Ok, progress slowly but surely. It turned out I had a CNAME entry in my dns that was throwing off my A zone entries. Now if I ping anything.mysite.com I get a reply. So the DNS issue is now working.

                            Thanks for bareing with me everyone and for all your help. My new issue is as follows:

                            I have an alias set up in my apache config file that looks like this:
                            Alias *.mysite.com "C:/Program Files/Apache Group/Apache2/htdocs/hydra/index.php"

                            Now my assumption is that if I type in mcslug.mysite.com it will ACTUALLY be forwarded to the index file referenced above, I can then code php into that page that will handle the url variables and do the work I want.

                            My problem is it doesn't re-direct to that page, it goes directly to the default apache welcome page. I think it's just jumping right over that line, (or perhaps I just have it typed wrong) I've also been reading up on virtualhosts (since etully recommended it) but I don't understand how that would help me? I tried putting this in for my virtualhost:
                            <VirtualHost 127.0.0.1>
                            DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/mysite"
                            ServerName *.mysite.com
                            </VirtualHost>

                            but my understanding is that virtual hosts are more for subdomains or running second domains on the same box.

                            As for the dns issues and changing companies, none of this is live right now, it's all being done in house in a development environment, so I can call it what I want where I want using a local ip and it works just fine.

                              This is my virtual host entry. Obviously, it's for Unix file system so you should replace with C: stuff but it might point you in the right direction:

                              <VirtualHost *:80>
                              ServerAdmin webmaster@mydomain.com
                              DocumentRoot /usr/local/sites/www.mydomain.com/htdocs
                              ServerName www.mydomain.com
                              ServerAlias mydomain.com
                              ScriptAlias /cgi-bin /usr/local/sites/www.mydomain.com/cgi-bin
                              ErrorLog logs/mydomain.com-error_log
                              CustomLog logs/mydomain.com-access_log combined
                              </VirtualHost>

                                As for why I use <virtualhost>'s: We don't even have a default web site set up - we just do all our sites on the box with virtualhosts.

                                I think the key is the:
                                *:80
                                And maybe the server name and server alias.

                                I know more about PHP than Apache configs so I can only help with my limited knowledge of Apache. I'm sure there are sysadmins out there who can help you much more with that part.

                                  Slow but steady steady but slow, IIS works, but apache is quirky:
                                  Ok, I've got the redirection sort of working. Basically here's how it's working:

                                  I set up dns, so all *.mysite.com requests are going to the same ipaddress

                                  I pointed mysite.com to the web directory on my server located at "C:/Program Files/whatever....."

                                  Now when I type in anything.mysite.com into a web browser it auto-defaults to the index.html page located in my web directory

                                  First off, can I forward to any other page? or does it HAVE to redirect to index.html (I realize I can put whatever I want into index.html so this is not a big deal)

                                  Here's the next question, how do I access the variables in the url, or how do I set the url variables to begin with? I.E. if I type mcslug.mysite.com and it gets redirected to index.php, how do I reference the name mcslug in a variable, or am I missing a step?

                                  To elaborate on windows, I have IIS now working but in a different way. I have IIS working so that if I type in mysite.com/users/anything it forwards to the page I specified and I can access the variables. Here's how to do that:

                                  In IIS, setup a new virtual directory and call it users
                                  - Right Click on the new virtual directory and go to properties
                                  - change it's virtual directory path to a URL redirection
                                  - for the redirect to path, type in ;/;http://mysite.com/wherever/file.php?path=

                                  the previous statement says take any url that begins with mysite.com and ends with /anything and forward it to mysite.com/where/file.php, the ?path= sets a variable equal to whatever /anything. So in php, you can use $_GET['path'] and it is the /anything value

                                  That's how I got it to work in IIS. So now any pages like http://mysite/com/users/mcslug redirects to my php page and reads mcslug as the variable for pulling down my information.

                                  Now, how do I do this in Apache?

                                    mcslug wrote:

                                    First off, can I forward to any other page? or does it HAVE to redirect to index.html (I realize I can put whatever I want into index.html so this is not a big deal)

                                    I don't know about IIS. In Apache, you can specify what default filename it looks for. (In fact, you can specify a series of default filenames and if it doesn't find the first one, then it looks for the next and the next).

                                    mcslug wrote:

                                    Here's the next question, how do I access the variables in the url, or how do I set the url variables to begin with? I.E. if I type mcslug.mysite.com and it gets redirected to index.php, how do I reference the name mcslug in a variable, or am I missing a step?

                                    In the PHP page, use this code to figure out which subdomain was used:

                                    $domain = $_SERVER['SERVER_NAME'];
                                    ereg("(.+).yourdomain.com",$domain,$regs);
                                    $username = $regs[1];

                                    Yeah, the path solution will work. Of course, It's not sexy. The whole point of this was to be able to use:

                                    http://mcslug.mysite.com

                                    And you are sooooo close...

                                    This technique will work in different languages and on different web servers. Now that you have the DNS working correctly, the key is forwarding any request for that IP address (no whatever what domain was used) to the main directory where you can then use the PHP $_SERVER['SERVER_NAME']; variable to determine which username appears before "mysite.com".

                                    Then you can do anything you want. You can include(); some file. You can read from the database and find content specific to that user. Whatever you want.

                                      Etully, once again, thanks for all your help

                                      New scenario, apache now forwards all requests for anything.mysite.com to the index page in the virtual directory I specify. Problem is, I can't direct it to a specific file, it defaults to index.html.

                                      So what I did was put:
                                      $domain = $_SERVER['SERVER_NAME'];
                                      ereg("(.+).yourdomain.com",$domain,$regs);
                                      $username = $regs[1];

                                      into the index.html file, I then echo'ed $username, but no luck. I tried just using basic php code like:
                                      <?php
                                      echo "welcome to the page"; ?>
                                      but that doesn't work either.

                                      I KNOW the php is setup in apache because if I go to one of my pages like http://mysite.com/login.php it works, and it's all php

                                      It's almost as if the php can't be read when it's in a .html file?

                                      So new questions for me to look at are now:
                                      1. How to specify the file for redirects in apache to take you to
                                      2. How to allow php to be used in .html files in apache

                                        It looks to me like you don't have .html files being parsed for PHP code. So you have two options for that,

                                        One is to make .html get parsed for PHP by adding an .htaccess file with this line:
                                        AddType application/x-httpd-php .html
                                        That would work but I don't really recommend that since it slows down your .html files and if you build a huge amazon.com sized web site, then you are forcing the server to check every .html file for PHP code which wastes CPU and RAM.

                                        Your other option is to make Apache look for index.html first, and if that doesn't exist, then look for index.php. You can do that by adding an .htaccess file with this:
                                        DirectoryIndex index.html index.php index.php3

                                        It will look for the files in that order.