Multiple addon domains, one htaccess file

477 views Asked by At

Lets say, my root domain name is main.com and I have two addon domains: addon1.com and addon2.com.

My script is already ready and I can see my websites like this:

    www.main.com/show.php?domain=addon1.com 

But, what I want is displaying websites through their domains. I mean when I open addon1.com, I want to see output of show.php?domain=addon1.com. Also these two domains are added as addon domain and their directory are:

    main.com/addon1.com/
    main.com/addon2.com/

I wrote a htaccess file to root folder (main.com/.htaccess)

    Options +FollowSymLinks
    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC]
    RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1

    RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC]
    RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1

But I'm getting 500 interval error. Any advice?

Thanks in advance.

2

There are 2 answers

1
Jon Lin On

Your rules are looping. The /show.php is going back through the rewrite engine and looping indefinitely. You need to add conditions so they don't loop:

RewriteCond %{HTTP_HOST} ^www\.addon1\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/show.php
RewriteRule ^(.*)$ /show.php?domain=addon1.com&$1

RewriteCond %{HTTP_HOST} ^www\.addon2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/show.php
RewriteRule ^(.*)$ /show.php?domain=addon2.com&$1
0
greg.arnott On

You needed to include "RewriteBase" to help out.

# tell mod_rewrite to activate and give base for relative paths
  Options +FollowSymLinks
  RewriteEngine on
  RewriteBase   /

# for the active site in hosting root folder,
# tell it not to look for a subfolder by skipping next rule
  RewriteCond %{HTTP_HOST}   ^(www\.)?main\.com [NC]
  RewriteRule ^(.*)$         - [S=1]

# the domain-name = sub-folder automation
# thus addon-domain.com in /addon-domain(\.com)?/
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com
  RewriteCond %{REQUEST_URI} !^/%1
  RewriteRule ^(.*)$         %1/$1 [L]

# to answer your question swap the above 
# domain-name = sub-folder automation for this rule
  RewriteCond %{HTTP_HOST}   ([^.]+)\.com$ [NC]
  RewriteCond %{REQUEST_URI} !^/show.php
  RewriteRule ^(.*)$         /show.php?domain=%1&$1 [L]
# although, the above line may require this instead
  RewriteRule .              main.com/show.php?domain=%1&$1 [L]