Domain that shows another domains subdirectory - dns

Is it possible to have e.g. "domain.com" that shows "domain2.com/dir".
What I mean is, that instead of domain.com just redirecting, I want it to show e.g. "domain2.com/dir/subdir" as "domain.com/subdir"
All this is regarding to a CMS.
What I need is, that my frontend to my CMS is at domain.com. A customer is creating his account with a shorttag. E.g. "domain2.com". Then their unique URL to THEIR frontend is "http://domain.com/domain2.com".
What I need is, that domain2.com can show "http://domain.com/domain2.com" - so that the customers doesn't need to redirect their users to http://domain.com/domain2.com, but can simply just redirect to their own domain - domain2.com
Thanks in advance.

If you're using cPanel you can set up an addon domain that can point to a specific directory.
If you're just using apache you'll need to point the domain to another folder in the vhosts.
<VirtualHost *:80>
DocumentRoot "/home/user/domain.com"
ServerName domain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/home/user/domain.com/dir"
ServerName domain2.com
</VirtualHost>

you can use http header in your first page(domain2.com/dir/subdir) to redirect to second page
in php this is something like this (in index.php file in subdir):
<?php
session_start();
header('Location: http://domain.com/dir');
die();
?>

Related

htaccess 301 directive for SSL

I am trying to allow customers to have multiple domains, but 301 them to their "permanent" domain for canonical reasons. I am getting some strange activity, and am positive it has to do with my syntax, however I don't know where the issue resides.
I have a main domain - let's call it permanent_site.com Note: I have an SSL installed and working for "permanent domain"
I have multiple non-permanent domains that I want to permanently redirect to the "permanent domain". Now lets say I have 2 non primary domains: non_p_domain1.com and non_p_domain2.com.
Should this not work?
<VirtualHost *:443>
ServerName non_p_domain1.com
ServerAlias non_p_domain2.com
Redirect 301 / https://permanent_site.com/
</VirtualHost>
<VirtualHost *:443>
ServerName permanent_site.com
DocumentRoot /path/to/html
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCertificateFile /path/to/ssl/permanent_site.com.crt
SSLCertificateKeyFile /path/to//ssl/permanent_site.com.key
SSLCertificateChainFile /path/to/ssl/permanent_site.com.ca.crt
</VirtualHost>
The whole point in doing it this way is to prevent someone from hitting https://non_p_domain1.com and being fed an "unsecure page". Instead, I want them redirected to the permanent domain before they hit the html directory that has all the .htaccess directives.
from hitting https://non_p_domain1.com and being fed an "unsecure page"
All the non-primary domains also need to have an SSL cert installed. By the sounds of it, they don't?
If not, then the client won't (or should not) connect to your server, so they never see the redirect.

How to access to site by 2 address

I have a site now with address https://example.com/. How to make possible access to this site also by address https://example.com.html? What to write in htaccess?
What to write in htaccess?
Nothing special.
The question is not what to write but what to not write in .htaccess. And the answer is: do not write anything that links the site to one of its names (example.com or example.com.html). The same applies to the PHP source or configuration files.
The rest is just proper names registration, nameserver and Apache configuration.
Regarding the configuration of Apache, let's say the IP address of your web server is 1.2.3.4. The Apache configuration file (httpd.conf f.e.) now contains something similar to this:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
In order to let Apache know the domain example.com.html is the same as example.com you can add a ServerAlias to the <VirtualHost> block:
<VirtualHost 1.2.3.4:80>
ServerName example.com
ServerAlias example.com.html
DocumentRoot "/www/docs/example.com"
# Other configuration directives for domain example.com
</VirtualHost>
Assuming you already have the name and the name servers are properly configured to point to your existing server, restart Apache and it should work.
Read more about <VirtualHost> and ServerAlias

How to create a site instance per subdomain

I would like to create a web platform where each customer get its own site like uservoice.com
Example:
Main website : uservoice.com
Customer 1: cust1-subdomain.uservoice.com
Customer 2 : cust2-subdomain.uservoice.com
The objective is that the customer can enter its site via its own url & login page.
Does anyone know how to do that? How to avoid a sub-directory by subdomain and copy all the files? I am looking for a clean and scalable solution.
I think the solution is a name-based virtual host.
For example the domain cust2-subdomain.uservoice.com will display the content located in a different folder than your DocumentRoot but the address will be unchanged. The server will recognize the domain and send the appropriate content.
If you are using apache: You will need to uncomment this line in the httpd.conf file if not already uncommented:
Include conf/extra/httpd-vhosts.conf
Then you should edit /usr/local/apache2/conf/extra/httpd-vhosts.conf.
<VirtualHost *:80>
ServerAdmin you#uservoice.com
DocumentRoot "/usr/local/apache2/docs/uservoice.com"
ServerName uservoice.com
ServerAlias www.uservoice.com
ErrorLog "logs/uservoice.com/error_log"
CustomLog "logs/uservoice.com/access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin cust2#uservoice.com
DocumentRoot "/users/customers/cust2/WWW"
ServerName cust2-subdomain.uservoice.com
ServerAlias www.cust2-subdomain.uservoice.com
ErrorLog "logs/cust2/error_log"
CustomLog "logs/cust2/access_log" common
</VirtualHost>
The first section is for your site and the second one for cust2's site. So cust2 will put his site into the WWW folder located in his home directory. You will put your content in your old DocumentRoot. (You will need to customize /usr/local/apache2/conf/extra/httpd-vhosts.conf).

make all subdomains access website root files

Here's what I want to do:
Let's say i have www.mysite.com and it's a complex website with alot of files
I want to make fr.mysite.com, it.mysite.com, uk.mysite.com to access the file in the root website (ie: fr.mysite.com/jobs.php will actually load mysite.com/jobs.php but in the browser url it will show the link with subdomain).
I want to build a site with content from multiple countries and I want each country to be accessed with it's code as a subdomain. If I can do that I can then process the url in php and know what country code it's in the url.
Copying the entire site to each subdomain folder isn't an option.
Let me know if you have any idea on how to do that, I guess it's a .htaccess thingy but I can't figure it out .
Use ServerAlias in your VistualHost configuration: set it up as single virtual host where all sub-domains point into the same root folder:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias *.mysite.com
DocumentRoot "\path\to\your\site\"
...
</VirtualHost>
This is the most recommended way -- no need to involve URL rewrite here.

redirecting without changing URL

i want to redirect domain domain1.com to domain2.com completely but without changing domain1.com URL.
i thought i could do that with .htaccess but i found out that it is not possible because they are to different domains and i should use http:// in .htaccess rule so it would be an external rewriting not an internal rewriting,so the URL will change.
is there any other solution? is using iframe the only solution?
i have to add that i don't want to change DNS setting for these 2 domains.
If both domains point at the same server then you can setup your apache config to point both domains at the same document root.
NameVirtualHost *
<VirtualHost *>
ServerName domain1.com
DocumentRoot /www/mysite
</VirtualHost>
<VirtualHost *>
ServerName domain2.com
DocumentRoot /www/mysite
</VirtualHost>
However, I would recommend domain2.com redirects (with a 302 redirect in the .htaccess) because it will improve your search engine optimisation, as both sites will be considered as one. So if a GoogleBot finds domain2.com as a link in another site, it will add it as a pagerank to domain1.com.
If they run on the same webserver you could set domain2 as an ServerAlias for domain1.
I thought I once read you could give a flag to mod rewrite that it internally proxies the request to another domain, however I have never used this myself (if it even exists) and I can't honestly say I think it'll be great for performance.. (but maybe it is..)
But why would you want two different domains show the exact same website, without changing the hostname to, what you see as, the primary one. If I might ask?

Resources