skip to Main Content

We have an online service with 3 customers: Autoparts, CarExamples and Cars & More. This is the url structure:

  • example.com/autoparts
  • example.com/carexamples
  • example.com/carsandmore

One of the customers (CarExamples) wants to use their own domain (carexamples.com), but it has to load the content of example.com/carexamples, of course always using the original domain.

That means that:

  • carexamples.com should load example.com/carexamples
  • carexamples.com/about should load example.com/carexamples/about
  • carexamples.com/categories/trucks?p=1 should load example.com/carexamples/categories/trucks?p=1

We are using a LAMP environment (PHP v5.6). The domain example.com is located in /www/example/html in our server.

The current status of this issue is:

  1. Create an A record in the domain’s DNS manager console that points to the same server where example.com is being hosted.

  2. Add a virtual host for the custom domain

    <VirtualHost servername:80>
        ServerName carexamples.com
        ServerAlias www.carexamples.com
        DocumentRoot /www/example/html
    </VirtualHost>
    

But this would just load the same content of example.com when opening carexamples.com

It is worth noting that /www/example/html/carexamples is not a directory, it is a rewrite from /www/example/html/store.php?store=carexamples

Shopify does something similar: https://help.shopify.com/en/manual/domains/add-a-domain/using-existing-domains/connecting-domains#set-up-your-existing-domain-to-connect-to-shopify maybe that could help as a reference to this issue.

These are the existing rewrite rules in the .htaccess file:

# stores
RewriteRule ^([0-9a-zA-Z-]{2,50})$ /store.php?store=$1 [QSA,L]

# stores > categories
RewriteRule ^([0-9a-zA-Z-]{2,50})/([0-9a-zA-Z-]{1,50})$ /store.cat.php?store=$1&cat=$2 [QSA,L]

# stores > categories > items
RewriteRule ^([0-9a-zA-Z-]{2,50})/([0-9a-zA-Z-]{1,50})/([0-9]+)/([0-9a-zA-Z-]{1,100})$ /store.cat.php?store=$1&cat=$2&id_item=$3&item=$4 [QSA,L]

2

Answers


  1. If I understood your post correctly (correct me or clarify if this isn’t what you’re looking for)

    You need a separated vHost for each entry .. You’re looking at the wrong directory — This is an example — Though it should be self explanatory .. Just add /carexamples to the DocumentRoot

    <VirtualHost servername:80>
        ServerName carexamples.com
        ServerAlias www.carexamples.com
        DocumentRoot /www/example/html/carexamples
    </VirtualHost> 
    
    Login or Signup to reply.
  2. Have your rules like this in site root .htaccess:

    RewriteEngine On
    
    # per domain rewrite
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} !^(?:www.)?example. [NC]
    RewriteCond %{HTTP_HOST}:%{REQUEST_URI} ^(?:www.)?([^.]+)[^:]*:(?!/1/) [NC]
    RewriteRule ^ %1%{REQUEST_URI} [L]
    
    # stores
    RewriteRule ^([w-]{2,50})/?$ store.php?store=$1 [QSA,L]
    
    # stores > categories
    RewriteRule ^([w-]{2,50})/([w-]{1,50})/?$ store.cat.php?store=$1&cat=$2 [QSA,L]
    
    # stores > categories > items
    RewriteRule ^([w-]{2,50})/([w-]{1,50})/(d+)/([w-]{1,100})/?$ store.cat.php?store=$1&cat=$2&id_item=$3&item=$4 [QSA,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search