Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create subdomain for every subdir in docroot (with htaccess) ? 1

Status
Not open for further replies.

spavkov

Programmer
Jun 16, 2004
26
Hi you all!

i have a very important problem i want to solve so please help:

i would like to create a single .htaccess file for my Apache server (GoDaddy hosting linux server) that will allow me a subdomains for every subdir on my server's root:

for example: if my i have a server:
and i have 3 subdirs in the servers document root:
test1
test2
test3

i want that if user enters in browser that he gets redirected to

and

that he gets redirected to

and
that he gets redirected to

also users must not see in browser the subdirs, so after the redirection, if user clicks on the links on the pages the subdir name must not show in urls, it must looks like a real subdomain.

so if there is a link in page
to the page /contacts.html
and user click on this link, then in browser address box it must show:
and NOT LIKE THIS:


now im sure that this is possible to do with .hraccess file and modrw but i dont know how...

PLEASE HELP ME !!!!

anyone?
 
Obviously the ip address must be changed to fit your machine.

Code:
<VirtualHost [i]192.168.0.1[/i]:80>
    ServerAdmin admin@information.com
    ServerName test1.information.com
    
    Redirect / [URL unfurl="true"]http://www.information.com/test1/[/URL]
</VirtualHost>

<VirtualHost [i]192.168.0.1[/i]:80>
    ServerAdmin admin@information.com
    ServerName test2.information.com
    
    Redirect / [URL unfurl="true"]http://www.information.com/test2/[/URL]
</VirtualHost>

<VirtualHost [i]192.168.0.1[/i]:80>
    ServerAdmin admin@information.com
    ServerName test3.information.com
    
    Redirect / [URL unfurl="true"]http://www.information.com/test3/[/URL]
</VirtualHost>

M. Brooks
 
Hi M. Brooks!

thanks for your answer but this is not what i want...

i need this to be done via .htaccess file or by editing the Apache config files, but this has to work for ALL possible solutions of the user entered subdomains, so it must use ModRewrite engine of Apache...

so if user enters in webbrowser:

he must be redirected to a /whoknowswhat/ subdir of my site.

I need a general solution, that i will set up once (via .htaccess or httpd.conf) that will work for ALL FUTURE possible subdirs, so if i create new subdir in root, that users can find it via subdomain without the need of altering the configuration files...

sorry if i was unclear in first post...

thanks again...
 
Apache 2.0

php 4.3.10

mod_rewrite is available!!!



 
Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\..+\..*$ [NC]
RewriteCond /path/to/htdocs/%1 !-d
RewriteCond /path/to/htdocs/%1 !-l
RewriteRule ^(.*)$ [URL unfurl="true"]http://www.information.com/[/URL] [L,NS]

M. Brooks
 
Hi MrBrooks.

i tried your solution and its not working...

But it looks that the problem is not in the contents of the .htaccess file.

i turned on the wildcards dns feature of the server and whatever subdomain i enter i get this message:

This is the Plesk™ default page
If you see this page it means:

1) hosting for this domain is not configured
or
2) there's no such domain registered in Plesk.

For more information please contact Administrator.


any ideas how to enable this wildcards dns?

i think this is the problem.

regards



 
Thank you MrBrooks for all your help...

here is the code that worked 100% for me (based on your code)

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} .
RewriteCond %{http_host} !^[URL unfurl="true"]www.mysite.com[/URL] [NC]
RewriteCond %{http_host} ^([^.]+)\.mysite.com [NC]
RewriteRule ^(.*) [URL unfurl="true"]http://www.mysite.com/%1/[/URL] [R=301,L,QSA]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top