homepage Welcome to WebmasterWorld Guest from 23.23.12.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
my .htaccess code problem
code is doing well but got messed
enil

5+ Year Member



 
Msg#: 3289283 posted 4:37 am on Mar 22, 2007 (gmt 0)

Hello,

i am using the following code to redirect any subfolder to subdomain
i.e.
if someone types [test.domain.com...] then it will point to [domain.com...]
so it looks like a subdomain

======================================================
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^.htaccess$ - [f]

RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteCond %{HTTP_HOST}!^ftp.domain.com
RewriteCond %{HTTP_HOST}!^mail.domain.com

RewriteCond %{HTTP_HOST} ^([^.]*).domain.com
RewriteRule (.*) /%1/$1 [L]

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
=======================================================

now the problem is below
suppose two subdomains are there, i meant that to folders
domain.com/sd1 and domain.com/sd2
both are working well as
sd1.domain.com and sd2.domain.com

now suppose, i m goping to make one folder under sd1
i give the name 'sd2'
so url looks like sd1.domain.com/sd2/
but it will not work because i have already one subdomain named sd2
so anything under sd1.domain.com/sd2/ will be treated as domain.com/sd2/
my code ignores the subdomain part

anyone who knows this stuff please help me

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3289283 posted 1:04 pm on Mar 22, 2007 (gmt 0)

Good post! -- The problem is well-described.

There is no "perfect" solution, as all you can do is to minimize the chances for for "interference" by picking "likely-unique" subdomain-subdirectory names. You can either prepend a "tag" on the subdomain-subdirectory filepaths to distinguish them from main-domain subdirectories, or you can move all subdomain-subdirectories into one uniquely-named subdirectory, and put all the subdomain-subdirectories there.

As examples:

RewriteCond %{HTTP_HOST} !^(www¦ftp¦mail)\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /subd_%1/$1 [L]

Here, each subdomain is stored in a subdirectory with the prefix "subd_", so the file for URL foo.example.com/bar would be stored at example.com/subd_foo/bar
As long as "subd_bar" is not allowed as a "real" subdirectory under example.com, you're OK. You have to be careful not to allow creation of non-subdomain subdirectories in example.com that start with "subd_".


RewriteCond %{HTTP_HOST} !^(www¦ftp¦mail)\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /sub-d/%1/$1 [L]

Here, we're doing almost the same thing, except that files for each subdomain are stored under a subdirectory named "/sub-d". So the file for subdomain "foo.example.com/bar" would be stored at "example.com/sub-d/foo/bar" Here, your "exposure" to intereference is limited to one subdirectory name only.

Note that I compressed your three RewriteConds to one by using the "local OR", and escaped the literal periods in the regular expressions as recommended.

Also, replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim

enil

5+ Year Member



 
Msg#: 3289283 posted 5:46 am on Mar 23, 2007 (gmt 0)

Thanks a lot jdMorgan for this gr8 solution

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved