apachemod-rewritemod-alias

use Apache Alias instead of RewriteRule to serve HTML page


A simple Alias in Apache configuration not working -

Alias /url/path/some-deleted-page.html /url/path-modified/new-avatar-of-some-deleted-page.html 

It gives "page not found". However RewriteRule works as expected but it sends redirect status to browser. I want browser/user not to be aware of the redirect. Hence, I want to use Alias instead of RewriteRule. I want to confirm if mod_alias can be used to map individual URL.

I use ProxyPassMatch also which executes all html pages as PHP script. Also adding ProxyPass makes no diffrence.

ProxyPass /url/path/some-deleted-page.html !

Please help so that I can map individual URL (a bunch of them) with Alias instead of RewriteRule.


Solution

  • The purpose of mod_alias is to map requested URLs with a directory on the system running your httpd instance. It does not return anything to the browser (i.e. no redirection code, nothing). It is all done internally. Hence your client does not even know it is there.

    Request: http://www.example.com/someurl/index.html

    Configuration

    [...]
    DocumentRoot "/opt/apache/htdocs"
    Alias "/someurl/" "/opt/other_path/someurl_files/"
    [...]
    

    In this scenario, users asking for any URL besides /someurl/ would receive files from /opt/apache/htdocs.

    If a user asks for /someurl/, files from /opt/other_path/someurl_files/ will be used.

    Still missing in this example is a <Directory> definition for securing the Alias directory.

    You should read: https://httpd.apache.org/docs/2.4/mod/mod_alias.html


    Alias will cover the case where you need to point a certain URL to a particular directory on the file system.

    If you need to modify the filename (i.e. the client asks for file A, and you send back page B), you should use RewriteRule. And to hide the fact you changed the filename, use the [P] flag.

    This directive allows you to use regex, yet still use a proxy mechanism. So your client does know what went on, as the address in his address bar does not change.