Dinamically pointing multiple domains to a single domain's subfolder with .htaccess

In this example, I manage domain.com. Inside it, I have a store template in php that loads the selected store dinamically:

  • domain.com/store1
  • domain.com/store2
  • domain.com/store3

The nice urls are being generated by the .htaccess below. What's really being loaded in the back, is this:

  • domain.com/store/index.php?store=store1
  • domain.com/store/index.php?store=store2
  • domain.com/store/index.php?store=store3

Each store has internal links, such as these:

  • domain.com/store1/catalogue
  • domain.com/store1/catalogue/instruments
  • domain.com/store1/catalogue/instruments/guitars
  • domain.com/store1/electric-guitar/1337

It works exactly as expected. These are the .htaccess rules to make that work in domain.com. The store querystring (store1, store2, store3) in each RewriteRule determines which store is being loaded:

# permalinks
RewriteEngine on

# errors
ErrorDocument 404 /error.php?error=404

# ignore existing directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

#################################################

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

# store: catalogue
RewriteRule ^([0-9a-zA-Z-]{2,50})/catalogue/?$ store/catalogue.php?store=$1 [QSA,L]
RewriteRule ^([0-9a-zA-Z-]{2,50})/catalogue/([0-9a-zA-Z-]{1,75})/?$ store/catalogue.php?store=$1&cat=$2 [QSA,L]
RewriteRule ^([0-9a-zA-Z-]{2,50})/catalogue/([0-9a-zA-Z-]{1,75})/([0-9a-zA-Z-]{1,75})/?$ store/catalogue.php?store=$1&cat=$2&subcat=$3 [QSA,L]

# store: products
RewriteRule ^([0-9a-zA-Z-]{2,50})/([0-9a-zA-Z-]{1,150})/([0-9]+)$ store/product.php?store=$1&slug=$2&id_product=$3 [QSA,L]

Now, here comes the tricky part. Some of the clients, would like to use their own domains, so that store1.com/* loads the same content of domain.com/store1/* (without using a redirect).

Example:

  • store1.com => domain.com/store1/
  • store1.com/catalogue => domain.com/store1/catalogue
  • store1.com/catalogue/instruments => domain.com/store1/catalogue/instruments
  • store1.com/catalogue/instruments/guitars => domain.com/store1/catalogue/instruments/guitars
  • store1.com/electric-guitar/1337 => domain.com/store1/electric-guitar/1337

You get the idea.

All the domains (domain.com, store1.com, store2.com, store3.com) are configured in the same Apache Web Server environment (using virtual hosts).

The question is: Can this be implemented in a .htaccess in each one of the store's domain root path dinamically or inside the virtualhost .conf file? If so, how?



from Recent Questions - Stack Overflow https://ift.tt/3vG8FMm
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)