Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache mod_rewrite domain to subdomain?

I have this address http://www.example.com and have this page http://www.example.com/world. Can I do this with mod_rewrite,to my page become http://world.example.com ? Any link,tutorial,...,will be nice,if I can do this? And what will be with these links for example:

  http://www.example.com/world/some-other-page
  http://www.example.com/world/and-second-apge

will these links also be rewritten to :

 http://world.example.com/some-other-page
 http://world.example.com/and-second-apge

Another question,is this good for SEO ?

I'm sorry on my bad English.

like image 258
user147 Avatar asked Oct 10 '10 04:10

user147


1 Answers

Try this:

RewriteEngine On

RewriteCond %{http_host} ^domain.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC]

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^world/([a-z0-9\-_\.]+)/?(.*)$ http://$1.domain.com/$2 [QSA,NC,R,L]

so:

http://www.domain.com/world/page => http://world.domain.com/page
like image 117
Tech4Wilco Avatar answered Nov 06 '22 11:11

Tech4Wilco