Redirecting from subdomain to subfolder

Can someone help me with this?

I want to redirect:
http://tech.tbreak.com/[COLOR=“DarkRed”]2010/05/samsung-syncmaster-lcd-px2370[/COLOR]

to:

The bit in red above is dynamic and will change according to article. Also, I have urls like http://tech.tbreak.com/aboutus which needs to be redirected to http://www.tbreak.com/tech/aboutus.

How do I do this through the .htaccess file?

Works perfectly.

Thanks, ScallioXTX.

You need to create a .htaccess file with RewriteRules. In order to use RewriteRules you first need to enable the RewriteEngine. So the first line is


RewriteEngine On

Then, if the domain is tech.tbreak.com, can be encoded as follows


RewriteCond %{HTTP_HOST} ^tech[COLOR="Red"]\\[/COLOR].tbreak[COLOR="Red"]\\[/COLOR].com$ [NC]

Where [NC] stands for NoCase, i.e. case insensitive, such that [noparse]Tech.tBreak.com[/noparse] will also be rewritten, for example

Then, you need to redirect the requested URL to the subdirectory:


RewriteRule .? http://www.tbreak.com/tech%{REQUEST_URI} [L,R=301]

%{REQUEST_URI} is the requested URL, which will be appended to /tech to get the correct URL. [L,R=301] ends this rewriteblock ([L]) and tells apache to redirect ([R=301])

All together:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^tech[COLOR="Red"]\\[/COLOR].tbreak[COLOR="Red"]\\[/COLOR].com$ [NC]
RewriteRule .? http://www.tbreak.com/tech%{REQUEST_URI} [L,R=301]

:slight_smile: