2016-07-05 65 views
1

工作,我想創建一個別名「/博客」到「/家/ MYDOMAIN /博客」所以,當我要求http://www.mydomain.ca/blog/myfile.html返回/home/mydomain/blog/myfile.html別名不是在Apache 2.4

<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.

我在做什麼錯?

+0

你重新啓動了服務器嗎?將'LogLevel'設置爲'info'並檢查訪問/錯誤日誌。 – hjpotter92

+0

我得到這個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,如Gecko)Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36「 – Etienne

+0

您的服務器正在偵聽端口443,虛擬主機定義爲端口80. – hjpotter92

回答

1

看來你需要在/etc/hosts中添加行申報www.mydomain.ca和www2.mydomain.ca是本地主機

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

至少它爲我工作