I have an application which uses a main domain (domain.com) and I want to be able to point other domains to the same content without needing to maintain separate instances of the code. The application is contained with a folder on the main domain and this folder is not accessed by search engines etc so I am not worried about SEO etc. All of the domains will be on the same server running Apache.
I would like to ensure that the domain name stays as the user originally typed it rather than redirect to domain.com as the purpose of this is so multiple customers can use the code but with the application branded to them using their colours, logo etc using settings taken from a MySQL database.
For example, a user goes to newdomain.com and they see a login form which is a local stored within /home/newdomain/public_html - on successful login they are directed to /folder which contains the application but rather than be directed to newdomain.com/folder which is empty I would like them to be redirected to domain.com/folder (i.e. /home/domain/public_html/folder) but still see newdomain.com/folder in their browser so it is transparent to them.
I tried the below https://stackoverflow.com/a/9521102/1278201 using htaccess but it changes the URL to domain.com:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/%{REQUEST_URI} [R=301,L]
I also found a post which mentioned using Apache config which seemed a better option as I am not concerned about SEO but am not sure if I can use this to only redirect one folder (i.e. don't redirect webroot, just redirect /folder) https://stackoverflow.com/a/3849129/1278201:
NameVirtualHost *
<VirtualHost *>
ServerName domain.com
DocumentRoot /home/domain/public_html/folder
</VirtualHost>
<VirtualHost *>
ServerName newdomain.com
DocumentRoot /home/domain/public_html/folder
</VirtualHost>
I also found posts pointing out possible issues with sessions and SSL certificates https://stackoverflow.com/a/140008/1278201 both of which are used in the application. I am happy to install a separate SSL certificate per domain but could any of the above redirects "break" sessions? Obvioulsy if someone logs in to newdomain.com/folder and then goes to domain.com/folder they would need to login again but would the fact that domain.com/folder is redirecting to newdomain.com/folder have an impact on session security?
What is the best way to achieve the desired outcome?