Forum Moderators: phranque
excuse my ignorance...i am experimenting for a while, but no success ;(
With CP i made some subdomains, eg "forums.mydomain.com"
for the main site www.mydomain.com
(The sub folders corresponding to the sub-domains are all in the root folder as generated via CP)
I need .htacces/mod_rewrite for:
To access forums.mydomain.com in the browser and it should redirect to "www.domain.com/forums"
and the name in the browser should stay forums.domain.com
(I thought this is brain-dead simple....but i really didnt get it to work...)
***
RELATED (the whole thing but backwards):
If i were to access www.domain.com/forums i need a rewrite so it goes to forums.domain.com
Thank you!
Georg
There is a world of difference in the end result.
.
I assume that you will want to redirect (www.)site.com/folder to subdomain.site.com to eliminate duplicate content first.
After that, I assume a rewrite from subdomain.site.com to site.com/folder/ will be required.
If that is the case, the question was asked several times in recent days, several recent threads have the answer you require.
RewriteEngine on
#
# Internally rewrite "translation-service" subdomain to /translation-services subdirectory
RewriteCond $1 !^translation-service/
RewriteCond %{HTTP_HOST} ^translation-service\.domain\.com
RewriteRule (.*) http://www.example.com/translation-services/$1 [L]
#
i assume this is a rewrite? It works except that the name in the browser changes. But it does its job.
Could you be so kind and explain what the difference would be in a redirect?
[edited by: jdMorgan at 10:36 pm (utc) on July 25, 2007]
[edit reason] example.com [/edit]
It's an external redirect, because you included "http://example.com" in the substitution URL. Because you did not specify otherwise, it will be a 302-Found (Temporary) redirect.
Coded properly, it would be something like:
# Internally rewrite "translation-service" subdomain to /translation-services subdirectory
RewriteCond $1!^translation-service/
RewriteCond %{HTTP_HOST} ^translation-service\.example\.com
RewriteRule (.*) /translation-service/$1 [L]
For example:
# Internally rewrite <subdomain>.example.com/<URLpath> to example.com/subs/<subdomain/<URLpath>
RewriteCond $1 !^subs/
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /subs/%1/$1 [L]
# Internally rewrite <subdomain>.example.com/<URLpath> to example.com/<subdomain/<URLpath>
RewriteCond %{ENV:Rewrite-Done} !^Yes$
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /%1/$1 [E=Rewrite-Done:Yes,L]
If you use the first method, then you can easily externally redirect direct client requests for the subdomain-subdirectories back to the subdomain to avoid duplicate content:
# Externally redirect client requests for example.com/subs/<subdomain>/<URLpath> to <subdomain>.example.com/<URLpath>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /subs/
RewriteRule ^subs/([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]
[edited by: jdMorgan at 10:02 pm (utc) on Mar. 13, 2009]