Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:37:31+00:00 2026-06-09T10:37:31+00:00

I am looking for Apache configuration that would allow for the following: Serve sub.domain.com

  • 0

I am looking for Apache configuration that would allow for the following:

  • Serve sub.domain.com as /%docRoot%/domain.com/sub, and
  • Would be able to do this for every hosted domain and any subdomain (ie. no per-domain vhost configuration)

I would be grateful for any solution, especially if there was no mod_rewrite involved (using mod_vhost_alias).

Note: There are some obvious solutions using mod_vhost_alias, but they either work for domain.com or sub.domain.com, none of them seems to cover both cases.

Have a nice day!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:37:32+00:00Added an answer on June 9, 2026 at 10:37 am

    Point *.domain.com to your document root (/%docRoot%/). You’ll need to do this in a vhost config. In that same vhost, add this:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/domain.com/
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
    RewriteRule ^/(.*)$ /domain.com/%1/$1 [L]
    

    If you want to avoid pointing www.domain.com to /%docRoot%/domain.com/www, then add a condition to exclude it:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/domain.com/
    RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
    RewriteRule ^/(.*)$ /domain.com/%1/$1 [L]
    

    EDIT:

    I assume I will still have to do this for every hosted domain (as the examples you’ve posted all refer to “domain.com”). Am I right?

    Yes, the above will only do the routing for domain.com, if you want to do this for all arbitrary domain.com, you’ll need to do something a bit more tricky:

    RewriteEngine On
    # here, %1 = subdomain name, and %2 = domain name
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.(.+)$ [NC]
    # make sure the request doesn't already start with the domain name/subdomain name
    RewriteCond %{REQUEST_URI}:%2/%1 !^/([^/]+/[^/]+)[^:]*:\1
    # rewrite
    RewriteRule ^/(.*)$ /%2/%1/$1 [L]
    

    The tricky thing here is the %{REQUEST_URI}:%2/%1 !^/([^/]+/[^/]+)[^:]*:\1 match. It posits the condition: %{REQUEST_URI}:domain.com/sub and makes sure the %{REQUEST_URI} doesn’t start with the domain.com/sub (back refrenced from previous match using %2/%1) using the \1 back reference.

    With this, you setup your vhost to accept every domain (default vhost) and any subdomain/domain will get routed. Examples:

    • http://blah.bleh.org/file.txt goes to /%docRoot%/bleh.org/blah/file.txt
    • http://foo.bar.com/some/path/ goes to /%docRoot%/bar.com/foo/some/path/
    • http://sub2.sub1.d.com/index.html goes to /%docRoot%/sub1.d.com/sub2/index.html

    EDIT2:

    Yes, I would very much like to get domain.com routed to /%docRoot%/domain.com/

    Try these:

    RewriteCond %{HTTP_HOST} ^(.+?)\.([^\.]+\.[^\.]+)$ [NC]
    RewriteCond %{REQUEST_URI}:%2/%1 !^/([^/]+/[^/]+)[^:]*:\1
    RewriteRule ^/?(.*)$ /%2/%1/$1 [L]
    
    RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+)$ [NC]
    RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)[^:]*:\1
    RewriteRule ^/?(.*)$ /%1/$1 [L]
    

    Basically the same thing, except a few of the regex needs to be tweaked to separate what a domain.com is like vs sub.domain.com. If you want to redirect www.domain.com to domain.com, that needs to happen before these rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed yesterday by looking into my apache error log that someone tried to
I'm looking for a framework that is better and easier to use than Apache
I am looking for a library to parse command-line parameters that would work identically
I have a small web.py Python application that I would like to serve under
I would like to make a URL rewriting configuration to d othe following: Allowing
I have an apache log I am looking to filter on HTTP status codes.
I'm looking for a way to programatically detect the location of the Apache config
Looking at some assembly code for x86_64 on my Mac, I see the following
Looking to do a bit of refactoring... Using NHibernate I have this query currently
Looking at the Ehcahce implementation of net.sf.cache.JS107, I am trying to achieve the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.