Forum Moderators: phranque

Message Too Old, No Replies

dynamic subdomain creation

dynamic subdomain creation php htaccess

         

franckmercado

3:59 am on Dec 5, 2006 (gmt 0)

10+ Year Member



Hello everyone,

I need some help to figure this one out:

I have recently moved my website (about ceramic) to a new server, anyway it's done with php

------------------------------------------------------------------
And for example it generates a dynamic web address like this:

www.mysite.com/piece.php?id=13 (if user views piece 13th)

anyway i want to show it like this:

nameofpiece13.mysite.com or
www.mysite.com/nameofpiece13
------------------------------------------------------------------

as you can see those are subdomain url's ... so my question is : what can I do to generate dynamic url's that look like subdomain url's without creating subdomains for every piece?

Can I acomplish that with .htaccess?

Hope you can give me a hand here ... anyway thanks for taking time to read.

Bye bye,

Franck

jdMorgan

2:28 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> as you can see those are subdomain url's ... so my question is : what can I do to generate dynamic url's that look like subdomain url's without creating subdomains for every piece?

If your host supports it, use wild-card DNS, so that *.example.com points to your server. Therefore, all subdomains are "defined".

> Can I acomplish that with .htaccess?

Yes and no. You must change the links on your pages to the 'friendly' format by modifying the PHP code. Then once a request for one of these friendly URLs is received by your server, use mod_rewrite or mod_alias to convert that request back into a call to your script. The link on the page is the 'real' URL, and then server-side code is used to map that 'real' URL to the 'real' server filepath to invoke the script.

I'm not in love with the idea of hundreds of subdomains. From an SEO perspective, I'd consider that "non-optimal" and would choose to use subdirectories or even hyphenated URLs instead. For a thorough discussion of using friendly URLs without that subdomain complication, see the thread about changing dynamic to static URLs in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim