apache - htaccess 重定向的奇怪行为

标签 apache .htaccess mod-rewrite redirect

我的目标是将整个域重定向到另一个域。旧域的每个 URL 都应重定向到新域的根 URL。

为了实现这一目标,我正在做:

redirect 301 / http://www.google.de/

问题是,当我在 http://localhost/randomPath 上测试它时,它会重定向到 http://www.google.de/randomPath,但不会到 google.de 的根 URL。

有人知道如何解决这个问题吗?

最佳答案

使用mod_rewrite对匹配主机名等规则进行更精细的控制:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ http://www.google.de/? [L,R]
目标 URI 末尾的

? 将删除任何现有的查询字符串。

关于apache - htaccess 重定向的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21192938/

相关文章:

html - 使用 .htaccess 删除 .html 和 .php 扩展名

php - 如何在 Heroku PHP 应用程序上启用基本身份验证?

.htaccess - RewriteEngine 所有重写都必须开启?

.htaccess - htaccess 重写破坏了相对路径

apache - jenkins 安装是否需要 Apache Web 服务器

.htaccess - 将非 www 重定向到 https 的 www

apache - 如何使用 mod_rewrite 避免链重定向?

php - 使用 PHP 的 exec() 函数重定向 shell 命令的输出

php - apache webserver 已经在 centos xampp 中运行

perl - 为什么我的共享变量在 mod_perl 中的 PerlChildInitHandler 和 PerlResponseHandler 之间被清除?