【问题标题】:htaccess - Invalid directory on 301 redirect and virtualHosthtaccess - 301 重定向和 virtualHost 上的目录无效
【发布时间】:2014-06-07 04:32:05
【问题描述】:

我有以下 apache 配置:

<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?请假设相同的情况适用于不同的子域。

【问题讨论】:

    标签: .htaccess mod-rewrite http-status-code-404 url-redirection subdomain


    【解决方案1】:

    在新浏览器的 root .htaccess 中首先尝试此规则:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-22
      • 2012-12-18
      • 2021-10-25
      • 2013-09-30
      • 2021-04-04
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多