Search code examples
php.htaccessblogshttp-redirect

Redirecting to a subdomain from another domain without changing its URL


I have a project where users can create their own profiles. And the profiles will have sub-domain URLs like robert.blogger.com. So if that user has some domain of his own like robert.com. Then I want every request for robert.com to redirect to robert.blogger.com without changing the URL.

The URL should show robert.com/home.html, robert.com/aboutus.html etc. but actually code should be run from robert.blogger.com/index.html, robert.com/aboutus.html etc.

Is this possible? If so, how can this be done?


Solution

  • This will work

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domainname.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.domainname.com
    RewriteRule ^(.*) user/user.php?username=%1
    ErrorDocument 404 /notfound.php
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*