Redirect domain homepage to a subdomain

(Firstly I am not sure which area this post should go to)

I want to redirect only the main homepage of website (and to

but existing inner domains such as should come out as as well as should remain as

the site is made in joomla.

please help. i can’t find a solution.

Not sure if i was able to provide correct specification through my question. But I think you got the requirement correctly. the redirect to the new subdomain should be only when appearing from or there should be no redirect when coming from other subdomains or subfolders. So do I need to list all the subdomains & subfolders in htaccess (or somewhere else)? if so how?

also the has different content than, so I am looking for redirect.

Thanks for the support!

Do you want it to be done with PHP? Otherwise it would be nice using .htaccess as far as I know. Your goal could be achieved through something like this.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www?\\.example\\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\\.php?$ [R=301,L]


If the above does not work then better to post/ask in Apache Configuration forums.


Very nice! For what the OP asked for, you came very close (you only redirected the empty {REQUEST_URI})!


When I approach a redirection question like this, I verbalize a “specification” so I can think about the code which will be required to perform the redirection. Your specification appears to be:

Redirect and to (is that using the same “main domain” or is that just another subdomain?) EXCEPT when a subdomain was requested via {subdomain} OR{subdomain’s subdirectory}.

Without a list of the subdomains, the second half of that EXCEPT part of the specification is impossible to accommodate.




Okay, perhaps I was trying to be TOO polite in saying that you need to provide more information so let me just go with NO subdirectories being redirected: Redirect and to EXCEPT when a subdomain was requested via {subdomain} OR when a subdirectory has been requested. Quite simply, that’s:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\\.)?example\\.com^ [NC]
RewriteCond %{REQUEST_URI} ^([^/]+)$
RewriteRule .?{REQUEST_URI} [R=301,L]

The first RewriteCond matches or (no case), the second ensures that the request is to the domain’s document root and the RewriteRule redirects EVERYTHING to the new domain.

The message is that it’s all in creating a specification which completely defines what you’re trying to do with your redirection.