Forum Moderators: phranque
I need help in setting up a folder inside the root directory as a subdomain.
Folder structure
www.mydomain.com
-- abcfolder
---- index.html
-- xyzfolder
---- index.html
When someone types abcfolder.mydomain.com it should go to www.mydomain.com/abcfolder/index.html but the url should still showup as abcfolder.mydomain.com/index.html.
Can someone help me do this?
Thanks in advance,
Suthaharan
The following code (picked from the forum) successfully redirect users to index.html page inside folder (for eg. httpddocs/folderabc/index.html)
RewriteEngine on
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST}!^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com(:80)?$
RewriteRule (.*) %1/index\.html
If I have physical subdomains inside my domain which is in the same level as httpdocs ...
/httpddocs
../abcfolder/index.html
../xyzfolder/index.html
/subdomains
../site1/index.html
../site2/index.html
My problem here is I wanted users to redirect to abcfolder/index.html when they type abcfolder.mydomain.com and to site1/index.html when they type in site1.mydomain.com.
Waiting to hear a reply while I am searching through the threads for an ideal solution.
Thanks,
Suthaharan
Did you completely flush your browser cache before testing this code?
Jim
If I have physical subdomains inside my domain which is in the same level as httpdocs ...
/httpddocs
../abcfolder/index.html (subfolder: abcfolder)
../abcfolder/foo.html (subfolder: abcfolder)
../abcfolder/foo2.html (subfolder: abcfolder)
../xyzfolder/index.html (subfolder: xyzfolder)
/subdomains
../site1/index.html (subdomain: site1)
../site1/foo.html (subdomain: site1)
../site2/index.html (subdomain: site2)
For subfolders:
I wanted the rewrite to work in such a fashion that I can display the contents of all the html/php files inside that subfolder. With the above code, I can only display index.html file. I wanted all the files inside subfolders also to get displayed.
Is there a way to check in .htaccess to see if the subdomain typed in the URL is actually a physical subdomain folder created under /subdomains directory and then to check if it is a subfolder created in /httpddocs?
Thanks in advance.
Suthaharan
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
# Skip rewrite if requested URL does not resolve to existing file or subdirectory in /<subdomain> path
RewriteCond %{DOCUMENT_ROOT}/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1/$1 -d
RewriteRule (.*) /%1/$1 [L]
Jim
Thanks for the reply. I am starting on with the cited links.
But the above code doesn't seem to work for me completely.
Now, if someone types http://abcfolder.example.com it is taking to http://abcolder.example.com/index.php page
If someone types the URL http://site1.example.com, it is picking up the index file from http://www.example.com/index.php and is not taking to the site1 subdomain as expected.
'/subdomains' is a folder in the same level of access as the folder '/httpddocs'
Thanks,
Sutha
[edited by: jdMorgan at 12:42 am (utc) on Mar. 10, 2008]
[edit reason] De-linked [/edit]
One extra question, is there any way to work with case-sensitive subdomains/subfolders?
For example,
http://subdomain.example.com >> http://www.example.com/subdomain
or
http://SubDomain.example.com >> http://www.example.com/SubDomain
Thanks in advance,
Sam
[edited by: jdMorgan at 12:41 am (utc) on Mar. 10, 2008]
[edit reason] example.com [/edit]
Jim
I've tried all your suggestions above to my situation, and I can't get it to work.
Let me give you some information:
1. My host is HOSTGATOR - I don't have access to http.conf. Everything I must do through .htaccess.
2. I have almost no knowledge of .htaccess.
3. I've implemented the above code, but it fails when I attempt to go to any of the pages of the subdomain securely. It gives me a certificate error (which I expected), but it shows the content of the main domain instead of the subdomain.
I've got a site which I'm trying to implement a test subdomain with all the functionality of the main domain (secure and all).
Thanks for your help!
Tom