Search code examples
.htaccessapache2.2

How to map following directory to a url using .htaccess?


I have few top level directory which contains sub directories e.g www which are treated as webroot ( for each subdomain e.g)

htdocs/myapp/admin/www     --- vhost subdomain admin.mysite.com 
htdocs/myapp/forum/        --- no sub domain 
htdocs/myapp/members/www   --- vhost subdomain members.mysite.com
htdocs/myapp/frontend/www  --- vhost subdomain frontend.mysite.com

I just wonder if its possible to access forum from each domain using .htaccess defined under each www directory e.g

admin.mysite.com/forum
members.mysite.com/forum
frontend.mysite.com/forum

I am searching for a solution that should ONLY work with .htaccess ( not with symblink etc )

Thanks for you kind support


Solution

  • Create following rewrite rules in each subdomain root .htaccess like this:

    RewriteEngine On
    RewriteRule ^forum/(.*)$ http://www.example.com/forum/$1
    

    Notice, the /forum has to be accessible via some URL first... w/o this, there is no way how to show the content using .htaccess