Apache 将url重定向到具有相同路径的其他url

Apache 将url重定向到具有相同路径的其他url,apache,.htaccess,redirect,Apache,.htaccess,Redirect,假设我必须访问不同的域: sub.domain.com 及 现在我想用相同的路径将sub.domain.com重定向到example.com。例如,如果我有路径sub.domain.com/the-path,我希望它重定向到example.com/the-path 我看到了:但它现在起作用了! 两个URL都指向一台服务器中的一个文件夹,但我希望sub.domain.com被重定向到example.com。在.htaccess文件中使用下面的代码时,它只重定向到表示sub.domain.com/

假设我必须访问不同的域:

sub.domain.com

现在我想用相同的路径将sub.domain.com重定向到example.com。例如,如果我有路径sub.domain.com/the-path,我希望它重定向到example.com/the-path 我看到了:但它现在起作用了! 两个URL都指向一台服务器中的一个文件夹,但我希望sub.domain.com被重定向到example.com。在.htaccess文件中使用下面的代码时,它只重定向到表示sub.domain.com/的基本页面,而对于其他路径,它不工作

RewriteEngine On
RewriteBase /
  RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$
  RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>

我该怎么办?

没有理由只重定向而不重定向。RewriteLog 2.2或LogLevel rewrite:trace8将清除它。请尝试:RewriteRule^http://www.example.com%{REQUEST_URI}[R=301,L]成功了!我只是把它向上移动了几行!事实上,我有另一条规则覆盖了这条规则!
RewriteEngine On
RewriteBase /
  RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www\.sub\.domain\.com$
  RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>