apache - 仅使用 htaccess 重定向基本 url

标签 apache .htaccess redirect

我只想将基本网址重定向到外部网站。

例如,我希望将 example.com 重定向到 anotherdomain.com,但我不希望 example.com/path重定向。

到目前为止,example.com/path 重定向到 anotherdomain.com/path。 :(

编辑:

首先感谢您的帮助! example.com 现在重定向到 another.com,而不影响 example.com 的子路径。

但是,理想情况下,m.example.com 不会重定向到 another.com。所以它实际上只是 example.com 重定向到 another.com

最佳答案

将此添加到 DocumentRoot 中的 .htaccess 中。我假设您在服务器上仅托管一个域。

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^m\.
RewriteRule ^$ http://anotherdomain.com [R,L]

关于apache - 仅使用 htaccess 重定向基本 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9418765/

相关文章:

java - 如何配置 tomcat 为单个应用程序中的不同端点使用不同的端口?

php - Apache 或 PHP 重定向到奇怪的 URL

php - 如何删除网址中的index.php

.htaccess - seo url 重写规则 - 使最后一个参数可选

php 位置重定向和特殊字符

php - 如何在代理后面使用 file_get_contents()?

linux - 是否可以在 linux 中重用 TCP 端口号

apache - 防止 mod_jk 在页面加载时显示/附加 index.cfm?&_modcfmlredirected

php - .htaccess 图片重定向

.htaccess - 修复 ERR_TOO_MANY_REDIRECTS