Forum Moderators: phranque

Message Too Old, No Replies

Folders as Subdomains...(no vhosts)

url rewriting

         

vijay trusva

12:04 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



Guys..
Let our site be "example.com"...
we have more no of users......

each user can view their images in
http://www.example.com/username1
http://www.example.com/username2
......

Is it possible to have URLS like

[username1.example.com...]
[username2.example.com...]
.......

and redirect them to
http://www.example.com/username1
http://www.example.com/username2
.....

Is it possible without having subdomains...?
Could u plz give me a better solution

regards
vijay

[edited by: jdMorgan at 2:37 pm (utc) on July 15, 2005]
[edit reason] Changed to example.com [/edit]

jdMorgan

2:35 pm on Jul 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



vijay,

Welcome to WebmasterWorld!

Is it possible to [rewrite subdomains to subdirectories]?

Yes. We have several recent threads [google.com] here on that subject.

> Is it possible without having subdomains...?

Those "www.username.example.com" URLs you described *are* subdomains.

> Could u plz give me a better solution

"Better" is a subjective term, so I really can't give a "better" solution without knowing all your selection criteria.

The basic steps to do what you asked about are:

1) Define the subdomains (or a wildcard to include all subdomains) in your DNS zone file.
2) Define the subdomains (or a wildcard to include all subdomains) in your virtual host setup (httpd.conf file).
3) Use NameVirtualHost or mod_rewrite to 'steer' each subdomain to the appropriate subdirectory.
Some hosting accounts are already set up to do step #2, so it's worth trying this, even if you cannot change httpd.conf.

Jim

Anyango

10:30 pm on Jul 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Vijay!

i agree with jdMorgan

you simply need to have a wildcard setup for your domain so that all subdomains reach your same directory as root directory of your main domain example.com

i mean if example.com's roo it

/home/admin/example.com/htdocs

then root of every sub-domain of example.com should also be the same

once that is done, you can simply put a small php script to parse out subdomain name from url and redirect accordingly.

Need some code?

jdMorgan

3:16 am on Jul 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest that you should not use a redirect since this makes the change visible to users and search engines. Use an internal rewrite -- either by using mod_rewrite, or by using 'include' or 'require' in php to actually serve the page, not redirect to a new URL.

Jim