Search code examples
apachehttp-status-code-404mod-alias

Alias not working on Apache 2.4


I want to create an alias "/blog" to "/home/mydomain/blog" so when I request http://www.mydomain.ca/blog/myfile.html it returns /home/mydomain/blog/myfile.html

<VirtualHost *:80>
    ServerName www.mydomain.ca
    ServerAlias www2.mydomain.ca

    Alias "/blog" "/home/mydomain/blog"
    DocumentRoot "/home/mydomain/web"
    <Directory "/">
            Options +FollowSymLinks
            AllowOverride None
            Require all denied
    </Directory>
    <Directory "/home/mydomain/web">
            Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
    </Directory>
     <Directory "/home/mydomain/blog">
            Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
    </Directory>

RewriteEngine on
RewriteCond %{SERVER_NAME} =www2.mydomain.ca [OR]
RewriteCond %{SERVER_NAME} =www.mydomain.ca
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

But when I try to request http://www.mydomain.ca/blog/myfile.html I get an error 404.

What am I doing wrong?


Solution

  • It seems you need to add a line in /etc/hosts to declare www.mydomain.ca and www2.mydomain.ca are localhost

    127.0.0.1    www.mydomain.ca   
    127.0.0.1    www2.mydomain.ca
    

    At least it worked for me