Web Hosting Forum | Lunarpages
News: October 6, 2008 - Submit Your Site for the October 2008 Site of the Month!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 12, 2008, 09:23:19 AM


Login with username, password and session length


Pages: [1] 2   Go Down
  Print  
Author Topic: Generating dynamic subdomains in apache  (Read 3120 times)
fandelem
Newbie
*
Offline Offline

Posts: 2


« on: February 11, 2008, 06:55:51 AM »

Hi All,

Here is what I want to accomplish:

A user signs up with a company name "Bob's Chiropractor".  I want to automatically genereate a subdomain: "bobschiropractor.mydomain.com" that will have an end result of redirecting to "mydomain.com/web/web.php?cid=1165".

Tom coms along, and the same thing:  Company name "Tom's Chiropractor".  I want to automatically genereate a subdomain: "tomschiropractor.mydomain.com" that will have an end result of redirecting to "mydomain.com/web/web.php?cid=1166".

My basic idea is:

-Create a subdirectory, along with an index.html file that has a META tag to redirect to the proper .php page
-Modify the vhosts file, creating a new entry with every company to link subdomain to new subdirectory

Questions become...
-Will this even work?
-What security do I also need to auto generate in which directories
-What piece of vhosts do I need to create (anyone have a sample copy I can mock up?)


Thanks so much for your time in advance!


Kyle
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #1 on: February 12, 2008, 09:29:04 PM »

Hi Kyle,

In reply on your questions:

Quote
-Will this even work?

Yes, why not? Wink

Quote
-What security do I also need to auto generate in which directories

This depends on that perms the process creating the sub directories will have. Basically, it should have right to create folders under the main directory.

Quote
-What piece of vhosts do I need to create (anyone have a sample copy I can mock up?)

You'll need to create a virtual host for each subdomain in Apache configuration like:

<VirtualHost *:80>
    ServerAdmin webmaster@subdomain1.mydomain.com
    DocumentRoot /www/subdomain1.mydomain.com
    ServerName subdomain1.mydomain.com
    ErrorLog logs/subdomain1.mydomain.com-host.example.com-error_log
    CustomLog logs/subdomain1.mydomain.com-access_log common
</VirtualHost>

BUT, your solution will require folders creation, virtual host addition and apache restarts which does not look good to me. How would I deal with this problem is:

1. Create a wildcard virtual host for "*.mydomain.com" so that all requests to subdomains go to this virtual host.
2. Setup a rewrite rule for it to redirect all requests to one page, say index.php, on it
3. Wrote up a PHP script taking the hostname the user came to, searching the redirect URL into a storage by it, i.e. mysql db, and redirecting to it. This script will be the index.php script on the wildcard host.

If you use this way, you only need to setup the above once and then add the subdomains in to the storage which appears to be more flexible solution than creating subfolders and modifying Apache configuration.



Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #2 on: March 10, 2008, 11:43:40 AM »

Hi Perestrlka,

I did the redirect with wildcard, from http://mysubdomainX.domain.com to a subdirectory with mysubdomainX files, but I would like to want to keep http://mysubdomainX.mydomain.com as URL. Instead, I have the URL as http://www.mydomain.com/mysubdomain/mypage.php.
1) Is it possible?
2)Can you show me how to do the script?

Tankyou in advance
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #3 on: March 10, 2008, 11:12:29 PM »

Hi Odaier,

I am sorry, your question is not clear for me. Can you please elaborate on it?

As for the script, unfortunately, I don't have it, but it should be easy to write for somebody with PHP knowledge. Additionally, a cgi script can be also used for that so if you know how to write up cgi scripts you can create the cgi for redirect.
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #4 on: March 11, 2008, 03:44:21 AM »

Hi Perestrelka,

Thank you for your reply.

Sory about my english - my first language is portuguese - I have some dificulties with it.
My main domain is http://www.webmemorial.com.br
My useres can create his own pages (unfortunely it is in portuguese, so I suppose that you will have dificulties to do it) as, for example a memorial for Ayrton Senna, a famous brazilian Formula-1 pilot. So, the subdomain created is http://ayrtonsenna.wbememorial.com.br.
In fact, my php script creates a subdirectory, not a subdomain, an, when the user types the URL as http://ayrtonsenna.webmemorial.com.br it is redirect to http://www.webmemorial.com.br/inicio.php?endinter=ayrtonsenna. (please, try it) It works so fine withi all the new "subdomains"  (in fact subdirectories) created by the users.
The problem is that I would like the URL in the the browsers keep the adress as a subdomain not as a subdirectory. In the case above, http://aystonsenna.webmemorial.com.br instead of http://www.webmemorial.com.br/inicio.php?endinter=ayrtonsenna
Do you know some way to do it?
Tank you in advance.
Omar
o.daier@gmail.com
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #5 on: March 12, 2008, 12:15:57 PM »

Hi Omar,

My Portuguese is more poorly than your English Wink. I think I got your question now. Did you create the wildcard virtual domain for the subdomains?
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #6 on: March 12, 2008, 12:34:22 PM »

Hi Perestrelka,

Yes, I created the wildcard virtual domain for the subdomains.
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #7 on: March 12, 2008, 09:22:58 PM »

Hi Perestrelka,

Yes, I created the wildcard virtual domain for the subdomains.

Does this virtual host have "UseCanonicalName Off" entry? If not, please try to add it and check how this will change the behavior of your redirect and URL appearance in the browser address bar.
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #8 on: March 13, 2008, 04:19:31 AM »

Hi Perestrelka,

Thank you for your reply again.

It is better that I explain to you that I am hosting my pages in a VPS with Apache, managed by Paralles Control Panel manager.

I have made some modifications in httpd.conf (wildcard virtual domain in one of then).
The UseCanonicalName Off was setted by default.

I am sending to you my httpd.conf, so you can verify all the entrys ?  Confused (plese tell me if I am abusing of your help - and, again sory about my english)

Regards,

Omar




Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #9 on: March 13, 2008, 09:32:00 PM »

Hi Omar,

I am glad to help and this problem appears to be interesting to me. I'm not showing your Apache config, which way did you send it to me for checking?
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #10 on: March 14, 2008, 04:50:45 AM »

Hi Perestrelka,

Oops!  Doh
Sory, I just forgot to send it.
 now I am sending the httpd.conf (httpd_conf.txt)

Regards,

Omar

* httpd_conf.txt (39.2 KB - downloaded 62 times.)
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #11 on: March 19, 2008, 05:08:46 AM »

Hi Omar,

Your Apache configuration looks good to me. What exact redirect does inicio.php script issue?
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #12 on: March 19, 2008, 05:24:38 AM »

Hi Perestrelka,

In fact, the inicio.php is the first page of a site, taking data from an MySql DB
So, when the user type ayrtonsenna.webmemorial.com.br, the progran identify (via a RewriteRule in .htaccess file) a code to link datas in the DB. So, instead a creat a subdirectory for each site (or subdomain) it only takes the specific data for that page in the DB file. Did I made it clear? (I have to learm more english before learn mor php or apache).
Regards,
Omar
Logged
perestrelka
Administrator
Master Jedi
*****
Offline Offline

Posts: 1055



« Reply #13 on: March 19, 2008, 10:17:42 PM »

Omar,

What is still not clear to me is this part:

"In fact, my php script creates a subdirectory, not a subdomain, an, when the user types the URL as http://ayrtonsenna.webmemorial.com.br it is redirect to http://www.webmemorial.com.br/inicio.php?endinter=ayrtonsenna"

How does the script issue the redirect?
Logged

Kind Regards,
Vlad Artamonov
odaier
Trekkie
**
Offline Offline

Posts: 12


« Reply #14 on: March 20, 2008, 07:13:13 AM »

Hi Perestrelka,

I am sory, I have meade the confusion.
I will try to be more clear:
The first idea was to create a subdomain for each user, but I did not found a way to do it   at the same time the user genereat a new account. I just know how to create a new subdomain only by Paralles Control Panel manager - so, in this case, create by me.
So, the idea change to create a subdirectory that contais some kind of data - images, sounds, films - that the user can upload an mantain the site organazed.
But, and a big but, all the pages are the same, in the main directory, changing only personal datas (name, age, etc) recordered in a DB with an ID for each user.
But, with the wildcard virtual domain idea, The user can acess his data using a "subdomain" name created by him (you can see the idea in action if you visit two or three "diferents" pages with diferent adress:
http://ayrtonsenna.webmemorial.com.br
http://beatriz.webmemorial.com.br
http://ricardo-bicudo.webmemorial.com.br
Eache one of this users (or adresses) has hs own subdirectories to images, sounds, videos, but the main files are the same - like inicio.php - although the apearence are diferent, changing only css properties and the data of each person that are in the DB.
The new user - and I am working to translate creation files to english - can create a new internet page with a lot of options, including an exclusive adress  - and use this adress to access the page just at the next moment.
OK, they can acess the pages using the exclusive adress they created, but the URL that they see in not the exclusive adress but  http://www.webmemorial.com.br/inicio.php?endinter=hisadress as the first page and the other pages with almost the same -as you can see if you click for instance videos in Ayrton Senna's page  you will see the page http://www.webmemorial.com.br/videos.php?endinter=ayrtonsenna
I donīt like this way to show the pages. I would like to show tham like subdomais.
I hope that with this explanation you can undrestand it. If not, please tell me that I can ask for a help here to someone hera that has a better englesh that I.
Thank you very much for your patience
Regards,

Omar


Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM