0

I have a web site for a customer on my server, the customer has his own domain.

I want keep the source files on my server and just to redirect the customer domain to show content of web site from my server.

  1. customer domain: www.a.com
  2. source file of web site: www.b.com/customer

I want to open in web browser www.a.com, show content from www.b.com/customer, but to keep www.a.com in address bar of web browser (including subfolders from www.b.com/customer).

Configuration: I am using managed server, cannot edit apache or php configuration, source web site is written in CodeIgniter. In CodeIgniter I put in config.php as base url: www.a.com. www.a.com is on one server (I have FTP access), there is .htaccess file in root:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^a.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.a.com [NC]
RewriteRule ^(.*)$ http://b.com/customer/$1 [L,R=301,NC]

On my server is www.b.com/customer, and in /customer folder there is also one .htaccess file with:

RewriteEngine On
RewriteBase /customer
RewriteCond $1 ^(application|system|private|logs)
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
RewriteCond $1^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
RewriteRule ^(.*)$ - [PT,L]
RewriteRule / index.php/$1 [PT,L]

to hide 'index.php' in web browser. So far works everything fine, upon call of www.a.com, user is redirected to www.b.com/customer, pages are correctly displayed. All links are shown as: 'www.a.com/some_page.php' and are also working. The only problem is that in address bar of web browser, the user sees 'www.b.com/customer'. I want to have there 'www.a.com/some_page.php' This is detailed problem description - please let me know if it is possible to solve? thanks and best regards, firestone

firestone
  • 1
  • 2

2 Answers2

0

I think this could be solvable trough this too -> create a sub-domain on your server which point to that directory www.b.com/customer. Than park his domain, and put as alias for your sub-domain.

For a solution trough the .htaccess i think it would be something like .htaccess rewrite to redirect root URL to subdirectory

Community
  • 1
  • 1
Danijel
  • 708
  • 1
  • 12
  • 29
0

(See EDIT below)
You should look at Virtual Hosts (or vhosts). All major web servers support vhost.

You should organize your customer files in your web root as,

---/var/www
   |
   --- customer_a/public_html
   |
   --- customer_b/public_html
   |
       ....
   |
   --- customer_z/public_html

For Apache2,
Create configuration file in site available directory for each customer,

customer_a -> /etc/apache2/sites-available/a.com.conf
customer_a -> /etc/apache2/sites-available/b.com.conf
...
customer_z -> /etc/apache2/sites-available/z.com.conf

Configuration for customer_a, (other should follow the same)

<VirtualHost *:80>
    ServerAdmin webmaster@a.com
    DocumentRoot /var/www/customer_a/public_html
    ErrorLog ${APACHE_LOG_DIR}/customer_a/error.log
    CustomLog ${APACHE_LOG_DIR}/customer_a/access.log combined
</VirtualHost>

For lighttpd,

$HTTP["host"] =~ "(^|\.)a\.com$" {
    server.document-root = "/var/www/customer_a/public_html"
    server.errorlog = "/var/log/lighttpd/customer_a/error.log"
    accesslog.filename = "/var/log/lighttpd/customer_a/access.log"
}

For nginx,
Create configuration file in site available directory for each cutomer,

customer_a -> /etc/nginx/sites-available/a.com
customer_a -> /etc/nginx/sites-available/b.com
...
customer_z -> /etc/nginx/sites-available/z.com

Configuration for customer_a, (other should follow the same)

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/customer_a/public_html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name a.com;
}

EDIT:

So for your case, (Just showing Apache2 Configuration)
Content of /etc/nginx/sites-available/a.com should be,

<VirtualHost *:80>
    ServerAdmin webmaster@a.com
    DocumentRoot /var/www/customer_b/public_html
    ErrorLog ${APACHE_LOG_DIR}/customer_a/error.log
    CustomLog ${APACHE_LOG_DIR}/customer_a/access.log combined
</VirtualHost>
Yash
  • 192
  • 1
  • 4