Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

Does an Apache Virtual Host Catch Subdomains and the Root Domain?

Apache needs an explicit apex name and a separate wildcard alias for subdomains. This guide explains matching order, DNS prerequisites, defaults and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

No. An Apache virtual host does not automatically cover both the apex (root) domain and its subdomains. Name the apex explicitly with ServerName or an exact ServerAlias, then add a wildcard such as *.example.com for subdomains. DNS must also direct those names to an address served by Apache.

A typical Apache 2.4 configuration is:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example
</VirtualHost>

What the apex domain and a subdomain mean

The apex, or root, domain is the bare name example.com. A subdomain adds a label before it, such as www.example.com, api.example.com or shop.example.com. Apache treats these hostnames as separate names when it matches a request to a virtual host.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That distinction is why a configuration containing only ServerName example.com does not claim www.example.com, and a configuration containing only ServerAlias *.example.com does not claim the bare example.com. The two forms must be combined when one site is intended to answer for both.

The configuration that serves the root and subdomains

Put the apex in ServerName and the wildcard in ServerAlias:

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example
</VirtualHost>

Here, example.com is an exact name, while *.example.com is a wildcard alias for hostnames below the apex. The wildcard does not turn the apex into a match.

Adding a separately documented hostname

You may list a commonly used name explicitly even when a wildcard also covers it:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example
</VirtualHost>

An explicit alias is useful when you want the configuration to show that www.example.com is intentional, or when that hostname may later receive a different redirect, policy or document root. Keep the wildcard only if other subdomains are meant to share this same virtual host.

Will *.example.com match example.com?

No. The wildcard requires a hostname below the suffix. It matches a subdomain such as blog.example.com, but the bare suffix example.com has no label for the asterisk to replace. Apache’s wildcard alias and the apex name therefore perform different jobs.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Request hostname Matching entry Result
example.com ServerName example.com Matches the exact apex name
www.example.com ServerAlias www.example.com or *.example.com Matches an explicit or wildcard alias
api.example.com *.example.com Matches the wildcard subdomain alias
A hostname outside the listed names None Falls back to the first virtual host for the selected IP and port

DNS is required before Apache can answer

Apache configuration does not create DNS records. The apex record and every intended subdomain must resolve to an address associated with the server. You can create individual records for names such as example.com, www.example.com and api.example.com, or use a DNS wildcard record when your DNS provider supports that design.

The Apache documentation states that you must first configure DNS to map the names to an IP address associated with the server. A correct VirtualHost block cannot compensate for a missing, incorrect or stale DNS record.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to verify in DNS

  • The apex domain has the expected address record, commonly an A record for IPv4 and, where used, an AAAA record for IPv6.
  • Each named subdomain resolves to an address on which the relevant Apache virtual host is listening, or a DNS wildcard covers the intended names.
  • The address and port reached by the client correspond to the address and port in the virtual-host configuration.
  • Old records, alternate IPv6 addresses and proxying services are not sending some users to a different server.

How Apache chooses a virtual host

Apache’s name-based virtual-host selection is a two-stage process. It first narrows the candidates by the destination IP address and port. It then compares the request hostname with ServerName and ServerAlias values among the virtual hosts available on that IP-and-port combination.

  1. Select the address and port. Apache considers the local address and listening port reached by the request, such as *:80.
  2. Compare hostnames. It checks the request hostname against exact names and aliases belonging to virtual hosts selected in the first stage.
  3. Use the default when nothing matches. If no hostname matches, Apache serves the first virtual host listed for that IP-and-port combination.

This ordering explains why a request can reach the correct server yet display the wrong site. If the hostname is absent from your aliases, Apache has no matching name and uses the first configured virtual host as the fallback.

Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Why configuration order matters

The first-listed virtual host is not a universal default for every address and port. It is the fallback within the particular IP-and-port set Apache selected. A request arriving on another address or port can have a different first-listed host and therefore a different fallback site.

Do not rely on listing order to make a hostname work. Add the hostname to the intended virtual host; use ordering only to define what unmatched requests should receive.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ServerName versus ServerAlias

Directive Best use Coverage
ServerName example.com Primary canonical name One exact hostname
ServerAlias www.example.com Additional known hostname One exact hostname
ServerAlias *.example.com Many intentionally shared subdomains Subdomains below example.com, not the apex

Use ServerName for the principal name you want the virtual host to represent. Use exact aliases for a small, controlled set of additional names. Use a wildcard when numerous subdomains are deliberately served by the same document root and policy.

Explicit aliases or a wildcard?

Neither approach is automatically superior. Choose according to how much control you need over individual hostnames.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Consideration Explicit aliases Wildcard alias
Hostname coverage Only the names listed are accepted One rule covers subdomains below the suffix
Individual control Clear and easy to give a name its own policy later All matching names initially share the virtual host’s settings
DNS maintenance Requires a record for each subdomain Can be paired with a DNS wildcard for many names
Unintended hostnames Lower chance of serving an unplanned name May serve any matching hostname that resolves to the server
Best fit A small, known set or separate application policies Many subdomains intentionally sharing one site

When explicit aliases are safer

List names individually when each subdomain represents a different application, customer, environment or access policy. The narrower list makes omissions visible and prevents a newly created DNS name from silently inheriting the same site.

When a wildcard is practical

A wildcard is convenient when all matching subdomains are designed to use one document root and the same Apache policy. It reduces repeated Apache entries, but it does not remove the need to manage DNS or to decide which names should exist.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a subdomain shows the first or default Apache site

The usual cause is a hostname mismatch. The request reached Apache, but no ServerName or ServerAlias in the eligible virtual hosts matched the requested name. Apache then served the first virtual host for that destination address and port.

Check the virtual-host names

  1. Confirm the request uses the exact hostname you intended, including the spelling and domain suffix.
  2. Ensure the apex is listed explicitly if the request is for the bare domain.
  3. Ensure the subdomain is either listed as an exact alias or covered by the wildcard alias.
  4. Check that the edited file is enabled and that Apache has loaded the change.
  5. Look for another virtual host on the same address and port whose order makes it the fallback.

Check the destination address and port

A matching alias is considered only among virtual hosts selected for the request’s destination IP and port. If DNS sends the hostname to another address, or Apache is listening on a different port than the one you configured, the expected block may never be considered.

Check DNS separately from Apache

Resolve the apex and each subdomain from a client network. If the result is not an address associated with this server, fix DNS first. If DNS is correct but the wrong site appears, inspect the Apache virtual-host names and ordering.

A practical setup procedure

  1. Choose the names. Decide whether the site should answer for only the apex, for specific subdomains, or for all intentional subdomains.
  2. Create DNS records. Point example.com and every required subdomain, or an appropriate DNS wildcard, to the server address.
  3. Define the virtual host. Set ServerName example.com and add exact aliases or ServerAlias *.example.com as required.
  4. Set the document root. Confirm that /var/www/example exists and has the permissions needed by Apache.
  5. Check for competing hosts. Review other virtual hosts using the same IP and port so an unmatched request does not unexpectedly land on another site.
  6. Reload Apache. Apply the configuration through your system’s normal Apache reload process after validating the file.
  7. Test each name. Request the apex, an explicitly listed alias, a wildcard-covered subdomain and an intentionally unknown hostname. Confirm that each produces the expected site or fallback.

Common configuration mistakes

  • Only the apex is named: ServerName example.com alone leaves www.example.com and other subdomains unmatched.
  • Only the wildcard is named: ServerAlias *.example.com alone leaves example.com unmatched.
  • DNS was assumed to be automatic: adding an Apache alias does not publish a DNS record.
  • The wildcard was treated as a security boundary: it covers matching names that resolve to the server, including names you may not have intended to publish.
  • The wrong virtual host was edited: hostname matching is limited to the virtual hosts on the selected address and port.
  • The fallback was mistaken for a match: seeing a page from the first-listed site does not prove that the requested hostname is configured.

Recommended patterns by site design

One site, apex plus a few known names

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAlias help.example.com
    DocumentRoot /var/www/example
</VirtualHost>

This pattern makes the accepted names explicit and is easiest to audit when the list is short.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One site, many shared subdomains

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    DocumentRoot /var/www/example
</VirtualHost>

This pattern combines the required apex match with wildcard coverage for subdomains. Add exact aliases when a particular name deserves separate documentation or future treatment.

Different applications on different subdomains

Use separate virtual hosts when applications need different document roots or policies. Give each block its own ServerName or exact aliases instead of placing every name under one broad wildcard.

What to remember

  • The apex domain is a separate hostname and must be named explicitly.
  • ServerAlias *.example.com covers subdomains, not example.com.
  • DNS must point the apex and intended subdomains to an address served by Apache.
  • Apache first narrows by destination IP and port, then matches the request hostname.
  • If no hostname matches, the first virtual host for that IP-and-port combination is served.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.