0

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.

1 Answers1

1

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.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • Thanks for the clarification. Please let me know how we can achieve it i.e. doing something similar to mod_rewrite without sending any 301, 302, 307, etc. to the browser/client. I have the practical use case to make it work. The Facebook Like/Share can be retain to new URL if old URL exists. We don't want to clutter code with dummy pages just to satisfy FB crawler. – Sharad Upadhyay Sep 26 '20 at 05:09
  • You do exactly what I posted here. `Alias "/the_url_you_want/" "/the_directory_where_the_files_are_on_your_system/"`. – Nic3500 Sep 26 '20 at 05:10
  • Please let me know how it is possible if html file name is changed? "some-deleted-page.html" is now "new-avatar-of-some-deleted-page.html" – Sharad Upadhyay Sep 26 '20 at 05:25
  • mod_alias maps URLs with directories. It will not handle the filename change. To do that, you need to use mod_rewrite. `RewriteRule` with the `[P]` flag will allow you complete control on your renaming rules. And with the `[P]` flag, it will act as a proxy, so *the client will never know* the filename does not match the requested page. – Nic3500 Sep 26 '20 at 05:33
  • 1
    I solved the problem with [P] flag. As Proxy is same as host server, I used `http://localhost/url/path-modified/new-avatar-of-some-deleted-page.html` as proxy destination. It worked. Please update the answer so that I can accept it. – Sharad Upadhyay Sep 27 '20 at 13:09
  • It's inaccurate to say mod_alias does not return anything to the client. It can be used to send 'external' redirects to the server. That's what the `Redirect` directives do. – Emmanuel Dec 11 '20 at 17:02