This .htaccess
file is useful for shared hosting environments where the number of Addon Domains is limited.
Instead of configuring real Addon Domains in cPanel or your hosting panel, you can simulate them using folders and Apache rewrite rules.
Place this .htaccess
file inside your public_html
directory. Then, create a folder for each domain you want to simulate. Use folder names that are different from the domain name for clarity:
public_html/
βββ .htaccess
βββ foo_site/
βββ bar_site/
Point your domains (e.g., foo.com
and bar.net
) to the same public_html
directory. Apache will internally redirect each request to the correct subfolder based on the requested domain.
foo.com
will load files from the folderpublic_html/foo_site
bar.net
will load files from the folderpublic_html/bar_site
RewriteEngine On
# Match domain: foo.com
RewriteCond %{HTTP_HOST} ^foo.com$ [NC]
RewriteRule ^(.*)$ /foo_site/$1 [L,QSA]
# Match domain: bar.net
RewriteCond %{HTTP_HOST} ^bar.net$ [NC]
RewriteRule ^(.*)$ /bar_site/$1 [L,QSA]
- Make sure
mod_rewrite
is enabled on your Apache server. - Use
[NC]
for case-insensitive domain matching. [L,QSA]
ensures query strings are preserved and no further rules are processed.- You can add as many domains/folders as needed by copying the
RewriteCond
+RewriteRule
blocks.
This approach effectively mimics Addon Domains using simple rewrite rules.