Go Back   SitePoint Forums > Forum Index > Host Your Site > Apache Configuration
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Mar 1, 2009, 14:52   #1
desbest
SitePoint Enthusiast
 
Join Date: Feb 2006
Posts: 32
I can point subdomains to subfolders, but not sub-subfolders. How can I?

I can point subdomains to subfolders, but not sub-subfolders. How can I?

Code:
RewriteEngine on


# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
#
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.hostingz\.org(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]
What that code does is redirect http://subdomain.hostingz.org to http://hostingz.org/subdomain. And it works!

But how do I modify the last line, the RewriteRule so that it redirects to sites/(then the subdomain).

So http://subdomain.hostingz.org --> http://hostingz.org/sites/subdomain.

How can it be done? And test it out first as
Code:
RewriteRule sites/^(.*) /%1/$1 [L]
or
Code:
 RewriteRule sites^(.*) /sites/%1/$1 [L]
Both does not work.
desbest is offline   Reply With Quote
Old Mar 1, 2009, 19:28   #2
Dan Grossman
Follow Me On Twitter: @djg
gold trophysilver trophybronze trophy
SitePoint Award Recipient
 
Dan Grossman's Avatar
 
Join Date: Aug 2000
Location: Philadephia, PA
Posts: 19,741
The URL you're matching is "subdomain.hostingz.org", which does not contain the word "sites", so it doesn't make sense for "sites" to appear in your pattern (left side of the rule).

Code:
RewriteRule ^(.*) /%1/$1 [L]
becomes
Code:
RewriteRule ^(.*) /sites/%1/$1 [L]
Dan Grossman is offline   Reply With Quote
Old Mar 2, 2009, 17:25   #3
desbest
SitePoint Enthusiast
 
Join Date: Feb 2006
Posts: 32
I tried it and I get this
Code:
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Any help anyone?
desbest is offline   Reply With Quote
Old Mar 2, 2009, 18:24   #4
dklynn
Hosting
silver trophybronze trophy
SitePoint Award Recipient
 
dklynn's Avatar
 
Join Date: Feb 2002
Location: Auckland
Posts: 11,070
db,

Yeah, DON'T use the EVERYTHING atom unless you know what you're doing (i.e., know how to prevent looping on the @#$% thing)!
Code:
RewriteCond %{REQUEST_URI} !^/?sites/
RewriteRule ^(.*) sites/%1/$1 [L]
IMHO, improper use of (.*) is the sign of someone who does not know/understand regex (as originated in desbest's code). If you want to learn something about regex, have a go at the tutorial linked in my signature.

Regards,

DK
dklynn is offline   Reply With Quote
Old Mar 2, 2009, 18:30   #5
desbest
SitePoint Enthusiast
 
Join Date: Feb 2006
Posts: 32
That code doesn't work either, but that's identical to the one Dan Grossman gave me.
desbest is offline   Reply With Quote
Old Mar 2, 2009, 19:19   #6
dklynn
Hosting
silver trophybronze trophy
SitePoint Award Recipient
 
dklynn's Avatar
 
Join Date: Feb 2002
Location: Auckland
Posts: 11,070
db,

Except that it will NOT loop if sites is in the {REQUEST_URI}.

Regards,

DK
dklynn is offline   Reply With Quote
Old Mar 2, 2009, 19:54   #7
desbest
SitePoint Enthusiast
 
Join Date: Feb 2006
Posts: 32
So whats the code then its still unresolved?
desbest is offline   Reply With Quote
Old Mar 2, 2009, 20:51   #8
Dan Grossman
Follow Me On Twitter: @djg
gold trophysilver trophybronze trophy
SitePoint Award Recipient
 
Dan Grossman's Avatar
 
Join Date: Aug 2000
Location: Philadephia, PA
Posts: 19,741
dklynn gave you a new RewriteCond to add, did you use it?
Dan Grossman is offline   Reply With Quote
Old Mar 3, 2009, 10:32   #9
desbest
SitePoint Enthusiast
 
Join Date: Feb 2006
Posts: 32
Thank's alot dklynn and everyone else who helped me so a solution could be found.
I needed help because I've got a site builder account creator, and would like to create subdomains on the fly.

Topic solved. Lock this thread.
desbest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 21:17.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved