Forum Moderators: phranque

Message Too Old, No Replies

When subdomain gets requested use a other directory

instead of the normal default directory

         

Raine

1:51 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



Good day everyone, i am new here

For starters i suck at .htaccess
I did a search for my question on this forum but did not find my answer.

My situation:
I have www.domain.com as my main domain.
I have www.addondomain.com as my addon domain (on the same account as domain.com)
I have images.addondomain.com as a subdomain

The Directories
www.domain.com >> /home/raine/public_html/
www.addondomain.com >> /home/raine/public_html/addondomain/
images.addondoman.com >> /home/raine/public_html/images/

The problem is that cpanel cannot make a subdomain of a addondomain inside it’s own dir...it must go in the root dir.

I was hoping somebody with some .htaccess skill can make one that will do the following:

-When images.addondomain.com gets requested
-Instead of using /home/raine/public_html/images/
-Use /home/raine/public_html/addondomain/images/

Who is going to be my hero!

Maybe something like this? (alternative)
RewriteCond %{HTTP_HOST} ^([^.]+)images\.example\.com [NC]
RewriteCond %{HTTP_HOST}!^www\.images\.example\.com
RewriteRule ^$ /images/%1/ [L]

I don't want the URL to change

[edited by: Raine at 1:57 pm (utc) on Oct. 25, 2007]

jdMorgan

2:13 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Specific solution (supports only images.example.com)
RewriteCond $1 !^addon/
RewriteCond %{HTTP_HOST} images\.example\.com
RewriteRule (.*) /addon/images/$1 [L]
#
# General solution (supports any add-on subdomain except "www")
RewriteCond $1 !^addon/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteRule (.*) /addon/%2/$1 [L]

The "!^addon/" RewriteCond prevents an 'infinite' rewriting loop. Flush your browser cache before testing any change to your code.

Jim

Raine

2:36 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



I think that won't work.

MAIN DOMAIN: www.maindomain.com
ADDON DOMAIN: www.addondomain.com
ADDON SUBDOMAIN: images.addondomain.com

With your solution when i visit images.addondomain.com
it will be translated to www.addondomain.com/addon/images/ right? (or i got it all wrong?)

Since the directory for images.addondomain.com is:
/home/raine/public_html/images/
and the directory for www.addondomain.com is:
/home/raine/public_html/addondomain/

I cannot access /home/raine/public_html/images/ with www.addondomain.com i can only access that directory with images.addondomain.com

So basically my question is:
Is there a way to make a .htacces that will make a subdomain use an alternate directory? (remember i cannot access that directory with www.addondomain.com)

If that is impossible or too difficult, maybe another solution is:
-When images.addondomain.com get requested
-Translate that to www.addondomain.com/images/
-Without changing the URL.
-This must also work if i use images.addondomain.com/uploads/example.gif
-That must be translated to: wwww.addondomain.com/images/uploads/example.gif
-Without changing the URL.

I hope you can help me with that.

[edited by: Raine at 2:39 pm (utc) on Oct. 25, 2007]

jdMorgan

2:51 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All of this depends on exactly how cPanel defines addon domains. Then you have to put the code in the proper directory based on where cPanel defines that "proper directory" to be.

If it differs from the directory for you main site, then perhaps you can use *nix symbolic links to allow access to the directory paths you need.

Jim

Raine

3:06 pm on Oct 25, 2007 (gmt 0)

10+ Year Member



Well that is true... the Correct directory for that images.addondomain.com is /home/raine/public_html/images/

So i guess the .htacces should go there.

I think the best solution is this one >>

-When images.addondomain.com get requested
-Translate that to www.addondomain.com/images/
-Without changing the URL.
-This must also work if i use images.addondomain.com/uploads/example.gif
-That must be translated to: wwww.addondomain.com/images/uploads/example.gif
-Without changing the URL.

Could you make an example of a .htaccess that will do the above?
I will test it out and see if it works and modify it too my needs.

Thanks for your time and patience.

jdMorgan

3:15 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, in order to finish this month, you're going to need to modify that code and test it; We here at WebmasterWorld are too far from the problem and can't see your server error log file and other information needed to deduce the problem and solution.

Jim