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 743699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:53:37+00:00 2026-05-14T08:53:37+00:00

I’m working through a problem where I want to select a different static content

  • 0

I’m working through a problem where I want to select a different static content file based on the incoming Host header. The simple example is a mapping from URLs to files like this:

  • http://www.example.com/images/logo.gif -> \images\logo.gif
  • skin2.example.com/images/logo.gif -> \images\skin2\logo.gif
  • skin3.example.com/images/logo.gif -> \images\skin3\logo.gif

I have this working with the following RewriteRules, but I don’t like how I have to repeat myself so much. Each host has the same set of rules, and each RewriteCond and RewriteRule has the same path. I’d like to use the RewriteMap, but I don’t know how to use it to map the %{HTTP_HOST} to the path.

<VirtualHost *:80>
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
    ServerName www.example.com
    ServerAlias skin2.example.com
    ServerAlias skin3.example.com

    RewriteEngine On

    RewriteCond %{HTTP_HOST} skin2.example.com
    RewriteCond %{DOCUMENT_ROOT}$1/skin2/$2 -f
    RewriteRule ^(.*)/(.*) $1/skin2/$2 [L]

    RewriteCond %{HTTP_HOST} skin3.example.com
    RewriteCond %{DOCUMENT_ROOT}$1/skin3/$2 -f
    RewriteRule ^(.*)/(.*) $1/skin3/$2 [L]
</VirtualHost>

The concept behind the rules is if the same filename exists in a subdirectory for that host, use it instead of the direct targeted file. This uses host based subdirectories at the lowest level, and not a top level subdirectory to separate content.

Update:
I want to revise the question to assume the hostname doesn’t match the subdirectory exactly, but does exist as a 1-1 map. Here would be the revised URL to file mapping.

  • http://www.example.com/images/logo.gif -> \images\logo.gif
  • skin2.example.com/images/logo.gif -> \images\s2\logo.gif
  • skin3.example.com/images/logo.gif -> \images\s3\logo.gif

For use with RewriteMap, I created this data file:

##  hostmap.txt -- hostname to subdirectory map
skin2.example.com    s2   # map skin2 to s2 directory
skin3.example.com    s3   # map skin2 to s3 directory

And changed the RewriteRules to use %{HTTP_HOST} directly in the map call, which seems to be working.

RewriteEngine On
RewriteMap hostmap txt:conf/hostmap.txt 
RewriteCond %{DOCUMENT_ROOT}$1/${hostmap:%{HTTP_HOST}}/$2 -f
RewriteRule ^(.*)/(.*) $1/${hostmap:%{HTTP_HOST}}/$2 [L]
  • 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-05-14T08:53:38+00:00Added an answer on May 14, 2026 at 8:53 am

    Try this rule:

    RewriteCond %{HTTP_HOST} ^(skin\d+)\.example\.com$
    RewriteCond %{DOCUMENT_ROOT}$1/%1/$2 -f
    RewriteRule ^([^/]+)/([^/]+)$ $1/%1/$2 [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Change display function. The difference is that in vb6 functions… May 14, 2026 at 10:54 pm
  • Editorial Team
    Editorial Team added an answer Assuming the web host is running Apache, You can assume… May 14, 2026 at 10:54 pm
  • Editorial Team
    Editorial Team added an answer Perhaps an approach like this (not tested): $(document).ready( function(){ $('input.volumetextbox:first').change(… May 14, 2026 at 10:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.