3

I have a Joomla site mysite.com.

I want to have the subpage mysite.com/example act like a separate website using a separate domain name anothersite.com.

Can this be achieved using DNS settings on the domain and htaccess?

Hosting sites at cloudaccess.net but want this solution for one-page sites and landing pages without using a whole other hosting account / joomla instance.

Thanks.

Nathan Todd
  • 73
  • 1
  • 5
  • Short answer: yes, there are lots of ways; so many, that without more details, this question could have endless possible answers. – IMSoP Apr 28 '15 at 21:04
  • Hi @IMSoP could you give an example of how to do this with htaccess? I've looked around on several occasions for how to do it and have yet to come across a solution. Thanks! – Nathan Todd Aug 20 '15 at 08:11
  • As my previous comment said, it's hard to answer this without more details. Click [edit] and describe the **exact situation** you're facing, rather than a vague hypothetical scenario. For instance, are the sites all on the same server? Are you looking to display a single landing page or be able to navigate a whole site? Are you controlling the whole server or using shared hosting? – IMSoP Aug 20 '15 at 08:33
  • Thanks @IMSoP, appreciated. – Nathan Todd Aug 20 '15 at 16:33

1 Answers1

0

If your hosting provider allows you to have "alias" domains, you can point the new domain at the existing code, and detect the hostname using RewriteCond:

  1. Start by configuring the new domain to display all the same content as the existing domain.
  2. In the Apache configuration (probably .htaccess on shared hosting) add a rule which detects requests for the new domain, and "rewrites" them to instead serve your specific page:

    RewriteCond %{HTTP_HOST} landingpage.example.com
    RewriteRule ^/$ /url/for/my/landing/page
    
  3. Add an additional rule afterwards so that other URLs on that domain redirect the browser back to the main site

    RewriteCond %{HTTP_HOST} landingpage.example.com
    RewriteRule ^/([^/].*)$ http://realsite.example.com/$1 [R=permanent,L]
    

A variation of this would be to map everything on the second domain to a directory (or, rather, a URL prefix) in the first domain, by combining those two rules:

RewriteCond %{HTTP_HOST} subsite.example.com
RewriteRule ^/(.*)$ /url/for/my/subsite/$1 [L]

Note: If Joomla thinks it knows the "correct" URL for the page, it may try to redirect away from your new domain. If so, that is the topic for a new question.

If, on the other hand, you want to use Apache configuration to force users accessing http://realsite.example.com/url/for/my/landing/page to be redirected to http://landingpage.example.com/, you could add something like this:

RewriteRule ^/url/for/my/landing/page$ http://landingpage.example.com/ [L,R=permanent]

Note: Depending on some environment settings I don't fully understand, you may need to change ^/ to just ^ in the patterns above.

IMSoP
  • 89,526
  • 13
  • 117
  • 169
  • 2. doesn’t work. It works when used like described here: http://stackoverflow.com/a/1328357/2342963 – medoingthings Dec 14 '16 at 20:11
  • 1
    @medoingthings Yes, see the note at the end: whether the `/` is included in the URL to be matched depends on the exact context of the rule, and `.htaccess` files seem to work slightly differently from full config files in that respect. – IMSoP Dec 14 '16 at 20:33