[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do i point a subdomain to a subdirectory?

Posted on 2008-10-11
8
Medium Priority
?
432 Views
Last Modified: 2013-11-22
My objective is to find out how to point a subdomain to an existing domain subdirectory.

Currently  www.domainname.com points to htdocs/domainname/ as the root directory

I created a subdomain,  subd.domainname.com by creating an A record for subd.domainname.com pointing to the IP address for domainname.com

I created a subdirectory  htdocs/domainname/subd and I want the subdomain subd.domainname.com to point to the subdirectory (but still show subd.domainname.com in the address bar)

The host operator says I must use MOD_rewrite to do this.

The current setup uses a Virtual Private Server running FreeBSD and Apache Web Server with mod_rewite enabled. the httpd.conf file points www.domainname.com and domainname.com to the document root htdocs/domainname/

I would greatly appreciate keeping in mind that not only am I at a novice level, I have cognitive deficits. [You would be surprised how good web related projects are as therapy; they teach and reinforce logical step-by-step thinking. For someone such as myself, who was once a highly educated professional,  learning to do this is a challenge. I try to find out first what to do, then learn from doing it. Thank you in advance.]
0
Comment
Question by:Brokenstick
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 1800 total points
ID: 22696737
It looks like you have access to the httpd.conf file. In that case it's better to make changes there.

One possible solution would be:
Create an additional <virtualhost...> container/dupliacte the existent one but now with ServerName being set to your subdomain and adjust the document root to the subfolder.

The other way is to use mod_rewrite within the existent virtual host section. You need a rule which checks the HTTP_HOST
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subd\.domainname\.com
RewriteCond $1 !^subd
RewriteRule ^/(.*) /subd/$1 [L]

Open in new window

0
 

Author Comment

by:Brokenstick
ID: 22698613
Thank you, Caterham. I would like to give this a try, so please indulge me for a bit. This is not as simple for me as it probably should be.

Since I do have access to the httpd.conf files, with respect to your first suggestion,

"Create an additional container/dupliacte the existent one but now with ServerName being set to your subdomain and adjust the document root to the subfolder."

I have two questions:

(1)  Do I understand correctly that if I duplicate the section in the httpd.conf file for the original domain.com,

<VirtualHost domainname.com www.domainname.com>
  ServerName www.domainname.com
  ServerAdmin webmaster@domainname.com
  DocumentRoot /usr/local/etc/httpd/htdocs/domainname
</VirtualHost>

Would I change the DUPLICATE to read as follows:

<VirtualHost domainname.com www.domainname.com>
  ServerName subd.domainname.com
  ServerAdmin webmaster@domainname.com
  DocumentRoot /usr/local/etc/httpd/htdocs/domainname/subd
</VirtualHost>

(Is this necessary to know: do I change the top line from domain.com www.domain.com also?  If so, would it be to just subd.domainname.com?)

(2) Do I need to make other changes elsewhere -- for example, to the Zone Record?

With respect to the MOD_rewrite alternative, I know this is really silly but: where does the code go? You stated: "within the existent virtual host section"  -in context it looks like that would also be in the httpd.conf file as well, but I am not 100% certain.  And if it DOES belong in the httpd.conf file, where would it go?


Would I take the ORIGINAL VirtyualHost entry (above) for domainname.com  www.domainname.com
and add your code, such as:

<VirtualHost domain.com www.domain.com>
  ServerName www.domain.com
  ServerAdmin webmaster@domain.com
  DocumentRoot /usr/local/etc/httpd/htdocs/domain
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^subd\.domainname\.com
  RewriteCond $1 !^subd
  RewriteRule ^/(.*) /subd/$1 [L]
</VirtualHost>

Thank you again.  I looked up the function of RewriteCond and RewriteRule and it helped me udnerstand how that part "works", but putting it all together is still daunting to me.

Brokenstick

0
 
LVL 10

Assisted Solution

by:srgilani
srgilani earned 200 total points
ID: 22700159
<<             Wrong Entry
<VirtualHost domainname.com www.domainname.com>
 ServerName subd.domainname.com
 ServerAdmin webmaster@domainname.com
 DocumentRoot /usr/local/etc/httpd/htdocs/domainname/subd
</VirtualHost>

>>

<<  Correct Entry

<VirtualHost subd.domainname.com>
 ServerName subd.domainname.com
 ServerAdmin webmaster@domainname.com
 DocumentRoot /usr/local/etc/httpd/htdocs/domainname/subd
</VirtualHost>

>>
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Brokenstick
ID: 22700475
Okay experts, thank you.

I have made the changes to the httpd.conf in accordance with both suggestions combined.

However, when entering http://subd.domainname.com in a web browser, Firefox returns "Page Load Error - Address Not Found"; E7 returns "Internet Explorer cannot display the webpage"

I suspect that the problem is probably with the zone record?

Initially, I had created an entry in the domainname.com zone record:

subdr.domainname.com IN A xxx.xxx.xxx.xxx

where the IP Address is the same as the IP Address for domainname.com

Giving it some thought, it seems to me that subd.domainname.com is not unlike the entry for www.domainname.com; so I dropped the IN A record and added IN CNAME:

subd.domainname.com IN CNAME domainname.com.

I will wait a bit until that propigates and check again.

If you have any other suggestions, I will appreciate hearing from you all.


0
 

Author Comment

by:Brokenstick
ID: 22704176
I must be really THICK.

I would like to know if I may split points and if so how to do it. I tried finding it and couldn't. So then I thought maybe I would send a message to a "Community Advisor."  I found many of them, but try as I might thirty ways to Sunday I could not find out how to send a message. If you click on any of the advisors, all I get is a profile. Period.

So I am sure I am missing something. I want to thank and reward BOTH of the individuals who helped me because they BOTH helped.

But I haven't a clue. <LOL>
0
 

Author Comment

by:Brokenstick
ID: 22704485
Almost a complete success!

            The zone record has propagated and subd.domainname.com correctly displays the content (index) page of the subdirectory htdocs/domainname/subd.

             The "however" is that the url also changes, and instead of displaying
http://subd.domainname.com/, the address bar displays http://www.domainname.com/subd/ instead.

              Did I do something wrong, or do I just need some additional code to ad the eyeliner to this pig's lipstick?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 1800 total points
ID: 22705724
Your virtual host configuration looks like an IP-based virtual host one (=one IP per each IP-based virtual host, http://httpd.apache.org/docs/2.2/vhosts/ip-based.html ).

For name-based virtual hosting (one IP per multiple virtual hosts, http://httpd.apache.org/docs/trunk/vhosts/name-based.html ), you must use the NameVirtualHost direktive. The matching is based on the HTTP_HOST header of a HTTP request and the ServerName/ServerAlias directives.
NameVirtualHost *:80
<VirtualHost *:80>
 ServerName www.domainname.com
 ServerAlias domainname.com
 ServerAdmin webmaster@domainname.com
 DocumentRoot /usr/local/etc/httpd/htdocs/domainname
</VirtualHost>
 
<VirtualHost *:80>
 ServerName subd.domainname.com
 ServerAlias www.subd.domainname.com
 ServerAdmin webmaster@domainname.com
 DocumentRoot /usr/local/etc/httpd/htdocs/domainname/subd
</VirtualHost>

Open in new window

0
 
LVL 10

Expert Comment

by:srgilani
ID: 22708423
I am sure your problem has been solve after above post of caterham_www.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question