0

I am running Linux Mint 21.3 Cinnamon, and installed XAMPP 7.4.33 because I want to test a web application using a particular version of PHP. XAMPP installs Apache of course, and the first thing I want to do is to get the Alias directive working.

XAMPP installs to /opt/lampp/
and inside there is a directory htdocs
and inside here, I created a directory called alias-test, and then 2 subdirctories called old and new.
So the structure is like this...

/opt/
  lampp/
    htdocs/
      alias-test/
        old/
        new/
          test.html

At this point, with Apache running, I can browse to http://localhost/alias-test/old/ and to http://localhost/alias-test/new/ and as expected, in both cases, I get an Apache-generated listing of the files in these directories – that is, the "old" directory shows as empty, and I can see the "test.html" file inside the "new" directory.

Now, what I want to achieve is to be able to navigate to http://localhost/alias-test/old/test.html and for Apache to load the file /opt/lampp/htdocs/alias-test/new/test.html. So in /opt/lampp/htdocs/alias-test/ I created a .htaccess file and put this inside...

Alias /alias-test/old /opt/lampp/htdocs/alias-test/new

Now if I navigate to http://localhost/alias-test/old/test.html I get an Apache error:

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

localhost
Apache/2.4.54 (Unix) OpenSSL/1.1.1s PHP/7.4.33 mod_perl/2.0.12 Perl/v5.34.1

So, what's going on? What have I overlooked to get this minimal viable example working?

0

1 Answer 1

1

As a server administrator when you're confronted with server errors the first place would be to look at logs on the server. Apache and other web servers will generally log the reason why they responded with a particular error.

In this case the reason for the error can be found in the context section of the Alias directive,

Context: server config, virtual host, directory

Since .htaccess is not listed in the context section, the Alias directive is simply not allowed in a .htaccess file.

Add the Alias in your main httpd.conf and/or the VirtualHost configuration snippet that gets included in your httpd.conf and it will work as expected.


Despite what many people continue to parrot: you do not need to use .htaccess files.

They are a last resort, never the first choice when you have admin/root rights, because they come with performance penalties .

The recommendation from the Apache project is:

In general, you should only use .htaccess files when you don't have access to the main server configuration file.
...
.htaccess files should be used in a case where the content providers need to make configuration changes to the server on a per-directory basis, but do not have root access on the server system.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .