别名不适用于 Apache 2.4

Alias not working on Apache 2.4

我想为“/home/mydomain/blog”创建一个别名“/blog”,所以当我请求 http://www.mydomain.ca/blog/myfile.html 它时 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>

但是当我尝试请求时 http://www.mydomain.ca/blog/myfile.html 我收到错误 404。

我做错了什么?

看来你需要在/etc/hosts中添加一行来声明www.mydomain.ca和www2.mydomain.ca是localhost

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

至少对我有用