仅使用htaccess重定向基本URL

4 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.

Thi*_*key 9

将此添加到您.htaccessDocumentRoot.我假设您在服务器上只托管一个域.

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^m\.
RewriteRule ^$ http://anotherdomain.com [R,L]
Run Code Online (Sandbox Code Playgroud)