Solved

Dynamic document root based on XHTML MP browsers...

Posted on 2006-10-19
3
225 Views
Last Modified: 2010-04-20
We are currently using apache version Server version: Apache/2.0.46. We want to change the documnent root of an virtual host dynamically based on XHTML MP browsers.

Example :
example.mobi (when browsed through browser. Documentroot should be > /home/sites)
example.mobi (when browsed through XHTML MP browsers [ie: mobile] Documentroot should be > /home/sites/mobi)

we have tried using the below rewrite condition any suggestion.

RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteRule    ^(.*)$        /%1/$1 [L]

- Vijay
0
Comment
Question by:minipra
3 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 17768733
Hi,

If you have plenty of sub-domains and every subdomain routes in another directory on the server, it's annoying to add every subdomain to the apache.conf (httpd.conf) file.

This can be done dynamically.

DocumentRoot /webhosts/

[...]

<VirtualHost *>
ServerAlias www.yourdomain.com
ServerName www.yourdomain.com
RewriteEngine  on
RewriteCond    %{HTTP_HOST}  ^yourdomain.com
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^www.*
RewriteRule    ^(.*)$        /www/$1 [L]
RewriteCond    %{HTTP_HOST}  ^(.*)\.yourdomain\.com
RewriteRule    ^(.*)$        /%1/$1 [L]
</VirtualHost>

As you can see, the DocumentRoot is /webhosts/. This is the directory where all other sub-directories for the sub-domains are located.

We use the RewriteEngine to decide which directory we want. The first RewriteCond is to route the domain without any sub-domain into the www directory. The second RewriteCond demonstrates how the third RewriteCond works with any subdomain.

www.yourdomain.com  =>  /webhosts/www/
muon.yourdomain.com  =>  /webhosts/muon/

Finally setup your domain as wildcard domain *.yourdomain.com in your DNS and off the fun goes!

R.K
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Website Test Question 6 128
connection string question 2 72
IPA - can it be run on a web server? 3 208
How to stress test an ASP.NET https website 3 82
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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