Apache mod_rewrite domain for subdomain?

I have this address http://www.example.com and this page http://www.example.com/world . Can I do this with mod_rewrite so that my page becomes http://world.example.com ? Any link, tutorial, ... would be nice if I can do this? And what will happen to 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 apologize for my poor English.

+5
source share
1 answer

Try the following:

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
+11
source

All Articles