【问题标题】:Alias not working on Apache 2.4别名不适用于 Apache 2.4
【发布时间】:2016-07-05 15:03:49
【问题描述】:

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

我做错了什么?

【问题讨论】:

  • 你重启服务器了吗?将LogLevel 设置为info 并检查访问/错误日志。
  • 我得到了这个 www.mydomain.ca:443 [MY IP] - - [05/Jul/2016:17:47:23 +0000] "GET /blog HTTP/1.1" 404 2307 " -" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36"
  • 你的服务器正在监听 443 端口,虚拟主机是为 80 端口定义的。
  • 我像这样更改虚拟主机:“”但我仍然收到错误 404。这是我得到的:“www.mydomain.ca:443 [MY IP] - - [05/Jul/2016:19:42:39 +0000] "GET /blog/ HTTP/1.1" 404 2307 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 "

标签: apache http-status-code-404 mod-alias


【解决方案1】:

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

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

至少对我有用

【讨论】:

    猜你喜欢
    • 2020-06-21
    • 2014-07-06
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多