Managing Resources using Apache mod_alias

Managing Resources using Apache mod_alias

In certain cases all of the services that an Apache host uses are stored in the DocumentRoot of that server. The DocumentRoot is a directory listed in the block of configuration for <VirtualHost>. This directory is intended to represent the various files, folders, and services on the file system that users access via HTTP. However, it is normal for administrators to provide HTTP access to a resource that is not located in the DocumentRoot on file system. For certain cases, although Apache may obey symbolic connections, this could be hard to sustain. It allows Apache to assign an Alias that links a place in the request to an alternate location.

This document describes how to manage resources on the file system using the Alias directive while still providing access through HTTP. In addition, this guide assumes that you have an Apache installation working and that you have access to change configuration files. If you have not installed Apache, you might want to find one of our installation guides for Apache or the installation guides for LAMP stacks. If you want a more comprehensive guide to Apache configuration, find the fundamentals of our Apache configuration and the layout of the Apache papers.

Creating Aliases

Virtual Host configurations usually specify a DocumentRoot which, by default, specifies a directory called public_html/  or public/.  If the root document for the virtual host abc.com  is/srv/www/abc.com/public_html/,  then the file located at /srv/www/abc.com/public_html/index.htm  will be returned by a request for http://www.abc.com/index.htm.

If the administrator were to retain the file system code/ resource at /srv/git/public/ but make it accessible at http://abc.com/code/,, an alias will be required. In this example this is accomplished:

Apache Configuration

DocumentRoot /srv/www/abc.com/public_html/
Alias /code /srv/git/public


Order allow,deny
Allow from all



Without the Alias instruction, a http://abc.com/code/ request will return the resources available in the /srv/www/abc.com/public_html/code/. folder. The Alias will therefore direct Apache to serve content from the directory /srv/git/public. The segment <Directory> allows remote users to access the directory.

There are a variety of important factors to remember when using the Alias Directive:

  • Directory blocks need to be generated after Alias has been declared for the destination of Alias. This makes it possible to allow access to and otherwise regulate the actions of certain pieces. That would be /srv/git/public in the example above.
  • In general, trailing slashes should be avoided in the Alias Directives. If the above read Alias /code/ /srv/git/public/  the request for http://abc.com/code, code, without a trailing slash, it will be served from the DocumentRoot.
  • The Alias directives must be generated either in the root-level configuration of the server (e.g. httpd.conf)  or in the <VirtualHost> configuration block.

In addition to Alias, Apache provides for an AliasMatch Directive that provides similar functionality. AliasMatch  includes an additional opportunity to alias a class of requests for a given resource to a place outside the DocumentRoot. Consider another fictitious abc.com virtual host configuration:

Apache Configuration

DocumentRoot /srv/www/abc.com/public_html/
AliasMatch /code/projects/(.+) /srv/git/projects/$1


Order allow,deny
Allow from all



In this example, resource requests for URLs such as http:/abc.com/code/projects/my_app and http:/abc.com/code/projects/my_app2 will be served in /srv/git/projects/my_app2 respectively. Nonetheless, http:/abc.com/code/projects will be accessed from /srv/www/abc.com/public html/code/projects/ instead of /srv/git/projects/ due to the /code/projects/(.+) trailing slash in the alias.

Although the possible use case for Alias is quite limited, the feature is very powerful to maintain a stable and well-organized web server.

Thank you !
    • Related Articles

    • Rewrite URLs using mod_rewrite and Apache

      You’ll learn how to rewrite the URLs using mod rewrite and Apache in this article. Rewrite a URL is a server-side operation which can serve contents from a position of a file system that does not exactly suit the client’s request. It could be helpful ...
    • Basics Information of Apache Configuration

      The Apache HTTP web server is the de facto standard for general HTTP services in many respects. Thanks to its large number of modules, it offers versatile support for proxy servers, URL rewriting, and granular access control. In addition, web ...
    • Tuning Of Your Apache Server

      Your Apache configuration settings have a significant impact on the output of your Microhost Cloud server. There are several tools that can be used to further examine the performance of your Apache server and make educated choices on how to start ...
    • Rule-based Access Control for Apache

      Apache provides a set of tools that allow administrators to manage server-provided access to specific resources. You can already know about authentication-based access controls, which allow visitors to authenticate the server before accessing ...
    • URLs Redirect with Apache Web Server

      You can learn how to redirect URLs with Apache in this section. Redirecting a URL allows you to return an HTTP status code that guides the client to a specific URL, making it useful for instances where a piece of content has been transferred. ...