Forum Moderators: phranque

Message Too Old, No Replies

Dynamic Subdomain creation in PHP on windows

How to map subdomain URLs to filesystem subdirectories?

         

sandykadam

12:59 pm on Jun 12, 2007 (gmt 0)

10+ Year Member



Hi Friends,

I'm a PHP developer from india. I have to work on dynamic subdomain creation process via php. I need to create folders of users who registers on site. And server platform is windows and control panel is plesk.

For time being i have created user folders like.
http://example.com/shop_stores/sandy/
http://example.com/shop_stores/mike/
http://example.com/shop_stores/john/

but i want to display as

http://sandy.example.com/
http://mike.example.com/
http://john.example.com/

there are some files in user folder to see that users site. For example you can view following link which i want to do.
<snip>

Also wherever i want to give href link i will be able to give
http://sandy.example.com/.

So can anyone please help me or guide how to do this kind of functionality.

Thanks in advance.

[edited by: eelixduppy at 1:04 pm (utc) on June 12, 2007]
[edit reason] removed url; delinked [/edit]

jdMorgan

3:06 pm on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sandykadam,

Welcome to WebmasterWorld!

This subject has been covered in-depth here at WebmasterWorld -- Have you tried a search?

The problem is in two parts: Generate links on your PHP pages to user.example.com/page, and then configure the server to accept wildcard subdomains and map them into subdirectories in the filesystem.

The only trick is that you should explicitly forbid the username "www" and restrict usernames to only lowercase a-z, or hyphen for the first character, and a-z, hyphen or numerals for subsequent characters. This will keep the subdomain path compliant with HTTP URL restrictions.

As for the rest, try searching for "subdomain subdirectory rewritecond http_host rewriterule [google.com]" and similar to find lots more on this subject.

Jim

sandykadam

7:03 am on Jun 13, 2007 (gmt 0)

10+ Year Member



Hi JDM,

Thanks for your reply.
I'm working on this first time so not very familier with htaccess and its functioning.

My server is windows and using IIS.

I have created user folders in [sitename.com...]
so user is sandy. But it shud display [sandy.sitename.com...] in browser or any inner page in sandy shud be access as sandy.sitename.com

So can you please guide me.

Thanks

jdMorgan

1:43 pm on Jun 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> My server is windows and using IIS.

Then unfortunately, there ia a problem: You'll need a host which supports ISAPI Rewrite -- an added-cost module for IIS that is similar to Apache's mod_rewrite. Then you should ask any questions in the Microsoft IIS Web Server and ASP.NET [webmasterworld.com] forum, where the level of expertise on IIS will be higher than here. :)

Jim