[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to create fake sub-domains on linux ?

Posted on 2007-10-15
Medium Priority
Last Modified: 2012-06-21

I have a Drupal website that has contents with such URLs:


I want to make fake subdomains like this:


my subdomains are limited and everything in the site wont be translated as a subdomain. for example, the following URL will stay intact:

i.e. help.example.com/... should not be translate to URL above.

any inputs is greatly appreciated.
Question by:MichaelPro
  • 2
  • 2
LVL 29

Accepted Solution

Jan Springer earned 252 total points
ID: 20081285
You create the appropriate records in DNS:

www.example.com.     IN      A        
cars.example.com.       IN     CNAME       www.example.com.

In Apache, you'll use virtual hosts:

DocumentRoot /var/www/html
ServerName www.example.com
<Directory "/var/www/html">
DirectoryIndex index.html index.php
Options ExecCGI FollowSymLinks

DocumentRoot /var/www/html/cars
ServerName cars.example.com
<Directory "/var/www/html/cars">
DirectoryIndex index.html index.php
Options ExecCGI FollowSymLinks


Author Comment

ID: 20094487
Is there a way to do this via htaccess? because using the above method, i would have to create entries manually, and i might as well just create sub-domains.
LVL 29

Expert Comment

by:Jan Springer
ID: 20095118
This is a subdomain:


The first action that will take place is the DNS lookup of 'cars.example.com'

Assisted Solution

sinisazg earned 248 total points
ID: 20106833
if you just want to enable that any wildcard subdomain (*.example.com) routes to the same web directory, in the definition of virtualhost just add

ServerAlias *.example.com

of course after adding the  DNS record as the fellow said above.

However, if you want to add automatic different routing so that you have just one virtual hosts and all other "hosts" are added simply by adding a line into a config file you need to use mod_rewrite. here an example (part of virtualhost configuration):

    RewriteEngine On
    RewriteMap subdomains txt:/etc/virtualhosting/subdomain/site16.map
    RewriteMap subdirectory_cgi txt:/etc/virtualhosting/subdomain/site16.cgisubmap
    RewriteMap scriptalias_cgi txt:/etc/virtualhosting/subdomain/site16.cgimap
    RewriteMap pub_subdomain_cgi txt:/etc/virtualhosting/subdomain/site16.pubcgimap
    # Avoiding CGI directory spoofs at domain level -- cannot let http://domain.com/sub/cgi-bin/foo.cgi source
    # multiple slash problem
    RewriteCond %{REQUEST_URI} ^[^?]*//.*$
    RewriteRule ^([^?]*)//(.*)$ $1/$2 [R,L]
    RewriteCond ${pub_subdomain_cgi:$1} ^(.+)$
    RewriteRule ^/(.*/cgi-bin)/(.+)$ %1/$2 [T=application/x-httpd-cgi]
    # Per directory CGI access - execute CGI scripts from within
    # ${documentroot}/cgi-bin/ -- ALLOWING FOR WILDCARDS
    RewriteCond %{REQUEST_URI} ^/cgi-bin/
    RewriteCond ${subdirectory_cgi:%{HTTP_HOST}\:*} ^(.+)$
    RewriteCond ${subdomains:%{HTTP_HOST}} ^(.+)$
    RewriteRule ^/cgi-bin/(.*)$ %1/html/cgi-bin/$1 [T=application/x-httpd-cgi,L]
    # Per directory CGI access - execute CGI scripts from within
    # ${documentroot}/cgi-bin/
    RewriteCond %{REQUEST_URI} ^/cgi-bin/
    RewriteCond %{REQUEST_URI} \.([^\./]+)$
    RewriteCond ${subdirectory_cgi:%{HTTP_HOST}\:%1} ^(.+)$
    RewriteCond ${subdomains:%{HTTP_HOST}} ^(.+)$
    RewriteRule ^/cgi-bin/(.*)$ %1/html/cgi-bin/$1 [T=application/x-httpd-cgi,L]
    # CGI script execution from the scriptalias directory
    RewriteCond %{REQUEST_URI} \.([^\./]+)$
    RewriteCond ${scriptalias_cgi:%{HTTP_HOST}\:%1} ^(.+)$
    RewriteCond ${subdomains:%{HTTP_HOST}} ^(.+)$
    RewriteRule ^/(.*)$ %1/html/$1 [T=application/x-httpd-cgi,L]
    # To emulate mod_rewrite
    RewriteCond ${subdomains:%{HTTP_HOST}} ^(.+)$
    RewriteCond %1/html/%{REQUEST_FILENAME} -d
    RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R] [L]
    # Lastly, the fallback document root
    # (Protect the interpreters directory)
    RewriteCond ${subdomains:%{HTTP_HOST}} ^(.+)$
    RewriteCond %{REQUEST_URI} !/interpreters/[-0-9a-zA-Z]+-script
    RewriteRule ^/(.*)$ %1/html/$1

The site16.sub file contains these:
shop.vexample.hr    /home/virtual/site16/fst/var/subdomain/shop
service.example.hr    /home/virtual/site16/fst/var/subdomain/service


www.shop.virtua.hr:*    *
shop.virtua.hr:*    *

other files are empty.


Expert Comment

ID: 20106834
site16.cgisubmap should be:)

service.example.hr:*    *
shop.example.hr:*    *

sorry took it from myoriginal server configuration, and forgot to edit that one.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question