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


Directory Mapping in htaccess for Subdomains

Posted on 2006-03-30
Medium Priority
Last Modified: 2008-01-09
I am hosting multiple websites with a company whose directory structure is thus... Primary Domain resides in public_html (which is where the htaccess file resides), And additional domains are subdirectories of this domain. I want to create a directory in public_html which is accessable by all the additional domains. As this is a shared sever I don't have access to the .conf file so it must be done via htaccess. Thanks for you help.
Question by:easttncs
LVL 27

Accepted Solution

caterham_www earned 1000 total points
ID: 16338158
> I don't have access to the .conf

So the only way to mapp the request would be mod_rewrite.

RewriteEngine on
# check the HTTP-Host. It must not begin with www.
RewriteCond %{HTTP_HOST} !^www\.
# check for a third-level domain
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com
# prevent looping
RewriteCond $1 !^specialfolder/
RewriteRule ^(.*) /specialfolder/$1 [L]
LVL 23

Assisted Solution

rama_krishna580 earned 1000 total points
ID: 16344213

Better way of getting this done is:

# Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
# Skip rewrite if no hostname or if subdomain is www
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\. [NC]
# Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.example\.com(:80)?<>/([^/]*) [NC]
# Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
RewriteCond %1<>%3!^(.*)<>\1$ [NC]
# Rewrite to /subdomain/path
RewriteRule ^(.*) /%1/$1 [L]


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 22 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