Similar to question posted here (but not related to sub directories): .htaccess redirect of domain name alias to main domain but must show up as the alias domain

I am trying to direct traffic from an alias domain I have to my site that is on the same server, while also keeping the alias domain in the browser address bar.

This is my original htaccess content which correctly redirects the user, but xyz.com appears in the browser which I do not want.

rewritecond %{HTTP_HOST} ^(www\.)?abc\.com$ [NC]
rewriterule ^ http://xyz.com/?foo [R=301,QSA,L]

This is my attempt to not only bring abc.com visitors to xyz.com but also have abc.com appear in the browser. This doesn't even load the site. Any ideas on a fix?

rewritecond %{HTTP_HOST} ^(www\.)?abc\.com$
RewriteRule ^$ /index.html [L]
  • Can you modify the DocumentRoot of the alias domain? If you point that to the same path as the "main domain"" you can do it without the RewriteRule-stuff. If you can't change that, then you have to use RewriteRules, in that case you probably have to replace /index.html with the correct relative path. So if, for example, the index.html of the main-domain is in the directory above you have to write ../index.html. – vstm Sep 28 '13 at 15:47
  • No access to DocumentRoot. abc.com is in a folder called aliasdomains and index.html is simply in the root folder so that is why I just wrote it as /index.html. Is my RewriteRule above still in an incorrect format? – John Montague Sep 29 '13 at 1:47
  • With RewriteRules you can't "break out" of the DocumentRoot, that means you can only point to files/folders inside your DocumentRoot and not in one of it's parent folders. So /index.html points to /path/to/aliasdomains/index.html (my solution with ../index.html wouldn't work either). You could just copy or symlink the file from the root folder to your aliasdomains folder. If that's not possible and your apache comes with the proxy module, you could do a proxy-rewrite with RewriteRule ^$ http://xyz.com/index.html [L,P]. – vstm Sep 29 '13 at 8:25
  • Problem resolved. As per @vstm comments I realized constraint on the folder hierarchy. I simply moved abc.com out of the aliasdomains folder and put it in the hosting root folder. Thanks. – John Montague Sep 29 '13 at 14:45
  • Since you resolved the problem, so that this question doesn't remain unanswered, please answer it below and select your answer when you can. – dan Oct 4 '13 at 11:42

I'm gonna assume each domain you're inquiring about are assigned separate document root folders on the same server.

I'll assume the document root for abc.com is in the /abc/public_html folder, and document root for xyz.com is in the /xyz/public_html folder.

Because you don't want xyz.com to show up and you want data from it, you have a couple of options.

If you use a linux server, you can turn all files (except .htaccess) in /abc/public_html folder as symbolic links pointing to the files in /xyz/public_html folder.

An easier way is to copy the files over so /abc/public_html has exactly the same contents as /xyz/public_html, but this option requires more disk space.

Update .htaccess so any requests to xyz.com are forwarded to abc.com so that there won't be duplicate content issues.

| improve this answer | |

Any time you redirect you are telling the browser to change the URL as it appears to the user. There are three approaches you could take for this problem.

  1. Serve both domains out of the same folder. This will mean that both domains have the same (duplicate) content. This solution works when both domains are served from the same server. You just need to set the virtual hosts to have the same DocumentRoot directory.
  2. mod_proxy in reverse proxy mode allows your domain to re-serve the contents from another domain. When it gets a page request, it fetches it from the other domain and serves it again. This will work even when the two domains are served on different servers. It will also create duplicate content and is slower than serving the content directly.
  3. Framed redirects. A framed redirect uses client side HTML frames to show the content of another domain.

    <frameset rows="100%,*" border="0">
    <frame src="http://othersite.example.com/" noresize frameborder="0">

    This solution is not great because:

    • It doesn't work well for SEO -- Google still directs users to the other site
    • The URL doesn't change as users navigate the site. This make is hard for users to bookmark or share content.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.