31

How can I have the following setup in apache?

http://server/ABC/* should be served by /var/www/ABC/*

http://server/PQR/* should be served by /var/www/PQR/*

Every other request should be served by /var/www/Others/index.php (a single file).

Thanks,

JP

  • 2
    For the first part of your question: [Alias](http://httpd.apache.org/docs/current/mod/mod_alias.html#alias) (`Alias /ABC /var/www/ABC` etc.) Leaving the DocumentRoot as /var/www/Others/ – plundra Dec 27 '10 at 12:18

2 Answers2

27

Use Alias:

Alias /ABC/ /var/www/ABC/
Alias /PQR/ /var/www/PQR/

Leave the document root pointing to /var/www/Others/index.php. It could do the trick. :)

Taber
  • 544
  • 3
  • 14
1

You can do this with mod_alias, which is part of the apache distribution.

http://httpd.apache.org/docs/current/mod/mod_alias.html

for serving everything else with the single file you would use mod_rewrite. This has many features and depending on your needs you might need to tweak that.. but something like this should work:

RewriteEngine on
RewriteRule ^(.*)$ /index.php?path=$1 [L]

you would put that in a .htaccess file in the document root.

Bastian
  • 10,403
  • 1
  • 31
  • 40
  • Pointing document root to index.php, but gives warnings when restarting apache, but *works*. I am thinking whether to use mod_rewrite or Tabers suggestion. –  Dec 29 '10 at 06:38