5

What I'm trying to do is a bit complicated and not sure if possible. Here it goes:

I have one main domain "maindomain.com" which corresponds to an event. Then I have several other domains, let's say "location1.com", "location2.com", "location3.com" which correspond to different locations where the event is held...

MAIN OBJECTIVE

The maindomain.com is hosted in a VPS (Virtual Private Server (Bluehost)). I've developed a website ready to display different info depending on the ?loc variable you pass by GET in the index.php. I want the other domains to point to the "maindomain.com", use the index.php?loc=1 (or 2 or 3) but keep their original domain name at the URL bar.

THE CHALLENGE

So the tricky part is when navigating within these location domains to keep the permalink clean in the URL bar:

location1.com/section1 --> loads --> maindomain.com/index.php?loc=1&sect=1
location2.com/section3 --> loads --> maindomain.com/index.php?loc=3&sect=3

Should I use domain/hosting options and/or .htaccess ??

EDIT

I think the more specific question is: how do I configure each location domain to point at the main domain where the hosted site is?

ANOTHER (BETTER) EXAMPLE

azsuperexpo.com/about --> loads --> thesuperexpos.com/index.php?loc=3&sect=2

--> Having superexpos.com the main domain where the website/database is hosted BUT what you see in the address bar is azsuperexpo.com/about

I want to have one central site which retrieves the info from its database but on the address bar of your browser you will see the different domains with correspondent permalinks to the different sections (loaded via php variables fetched from the database).

I think I will definitely have to use .htaccess to have the urls pretty like the example above. Would masking be an option? I know it's not recommended by search engines but if it's the only option I'm willing to give it a try.

Thanks a billion.

4

I hope I'm understanding this correctly. But it sounds likes you want to run three domains (maindomain.com, location1.com, location2.com, and location3.com) on a single web server and have each one point to a particular URL or folder on the web server. If so, you can do this with virtual hosts and the Nginx web server. A virtual host file describes a single domain and where the web server can find the files to be served. You can have multiple virtual host files, each one different from the others. When Nginx receives a request for "location1.com" it will load the "location1.com" virtual host and then point the requester to the right spot. Same for the other virtual hosts.

Nginx

Virtual host configuration files are stored in the '/etc/nginx/sites-available/default /etc/nginx/sites-available' directory. You will need to create four hosts files to make this work:

/etc/nginx/sites-available/default/etc/nginx/sites-available/maindomain.com
/etc/nginx/sites-available/default/etc/nginx/sites-available/location1.com
/etc/nginx/sites-available/default/etc/nginx/sites-available/location2.com
/etc/nginx/sites-available/default/etc/nginx/sites-available/location3.com

Virtual Host File

Configuring a host file is super easy too.

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

# Make site accessible from maindomain.com  
server_name maindomain.com; 

# Location of folder to serve files from  
root /var/www/maindomain.com;  
index index.html index.htm;

# Location of log files  
access_log /var/log/nginx/maindomain.com.access_log;  
error_log /var/log/nginx/maindomain.com.error_log;

I hope this helps!

  • Nice! Thanks for the solution. As soon as I try it out will let you know how it works. Happy new year! – Alvaro Jan 4 '17 at 17:34
  • You're welcome! Happy new year to you as well! :-) – Patrick Mullins Jan 12 '17 at 15:23
0

This is what worked:

1) I pointed (DNS) each domain (location1.com, location2.com...) to where maindomain.com is hosted.

2) In the hosting plan I added each domain as PARKED DOMAIN.

3) In the .htaccess I had to define each domain as follows:

# location1.com
# -------------    
RewriteCond %{HTTP_HOST} ^www\.location1\.com
RewriteRule ^$ index.php?loc_id=1 [L]
RewriteRule ^home$ index.php?loc_id=1&sect_id=1 [L]
# ...and so on for any other subsection

# location2.com
# -------------    
RewriteCond %{HTTP_HOST} ^www\.location2\.com
RewriteRule ^$ index.php?loc_id=2 [L]
RewriteRule ^home$ index.php?loc_id=2&sect_id=1 [L]
# ...and so on for any other subsection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.