1

無效的目錄,我有以下的Apache配置:htaccess的 - 關於301重定向和虛擬主機

<VirtualHost *:80> 
ServerName files.example.com 
ServerAlias files.example.com dev.files.example.com 
DocumentRoot /var/www/example/files 
</virtualHost> 

和我的.htaccess有:

RewriteCond %{HTTP_HOST} ^(.*)old-example.com [NC] 
RewriteRule ^(.*)$ http://%1example.com/$1 [R=301,L] 

但是,如果我指出我的瀏覽器files.old-example.com/myfile-1.2.zip它重定向到files.example.com/files/myfile-1.2.zip,顯然我得到一個404,因爲files目錄不存在/var/www/web/files內。

我該如何重定向到files.example.com/myfile-1.2.zip?請假定相同的情況適用於不同的子域。

回答

0

試試這個規則是你第一次從一個新的瀏覽器根目錄的.htaccess:

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^([^.]+)\.old-example\.com$ [NC] 
RewriteRule^http://%1.example.com%{REQUEST_URI} [R=301,L]