Forum Moderators: phranque

Message Too Old, No Replies

mydomain.com/subdomain => subdomain.mydomain.com

         

limbo_74

11:13 pm on Oct 3, 2004 (gmt 0)

10+ Year Member




www.mydomain.com/subdomain => [subdomain.mydomain.com...]
AND
mydomain.com/subdomain => [subdomain.mydomain.com...]

RewriteCond %{HTTP_HOST} ^(.+\.)*mydomain\.com/subdomain$ [NC]
RewriteRule /?(.*) [subdomain.mydomain.com...] [L,R]

This code not working.... help please...

jdMorgan

12:31 am on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



limbo_74,

Welcome to WebmasterWorld!

> www.mydomain.com/subdomain => http://subdomain.mydomain.com
> AND
> mydomain.com/subdomain => http://subdomain.mydomain.com

Anything following a single slash *is not* part of HTTP_HOST, so you have to move the subdomain name to the RewriteRule. For use in .htaccess:


RewriteCond %{REQUEST_URI} ^/subdomain1 [OR]
RewriteCond %{REQUEST_URI} ^/subdomain2 [OR]
RewriteCond %{REQUEST_URI} ^/subdomain3 [OR]
RewriteCond %{REQUEST_URI} ^/subdomainN
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^([^/]+)/(.*) http://$1.mydomain.com/$2 [R=301,L]

Very few webmasters need to use a rewrite like that; The more frequent request is for the opposite function, useful with wild-card DNS for hosting multiple subdomains under one hosting account. So just in case:

subdomain.mydomain.com OR www.subdomain.mydomain.com => www.mydomain.com/subdomain, using an internal (invisible) rewrite:


RewriteCond %{REQUEST_URI} !^/subdomain
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.mydomain\.com [NC]
RewriteRule (.*) /subdomain/$1 [L]

For use in httpd.conf, precede each RewriteRule pattern with a "/".

A more general solution, usable with any number of arbitrary subdomain subdirectories, is discussed in this recent thread, Rewrite arbitrary subdomains to subdirectories [webmasterworld.com].

Jim

limbo_74

1:01 am on Oct 4, 2004 (gmt 0)

10+ Year Member



thanks JdMorgan. And thanks welcome message...

sorry not working..

i like [domain.com...] to [forum.domain.com...]

your replay not working...