Php 使用.htaccess文件重定向到另一台服务器失败
我有Windows和Linux服务器。(在Linux服务器中管理域) 我的域名是 需要重定向到 我需要所有的请求来重定向到它 在这里,我尝试使用htaccessPhp 使用.htaccess文件重定向到另一台服务器失败,php,linux,apache,.htaccess,redirect,Php,Linux,Apache,.htaccess,Redirect,我有Windows和Linux服务器。(在Linux服务器中管理域) 我的域名是 需要重定向到 我需要所有的请求来重定向到它 在这里,我尝试使用htaccess RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.test.mydomain\.com$ RewriteRule ^/?$ "http\:\/\/192.97.XX.XX\Hello \/" 这将失败,因为您告诉htaccess查找www.test.mydoma
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.test.mydomain\.com$
RewriteRule ^/?$ "http\:\/\/192.97.XX.XX\Hello \/"
这将失败,因为您告诉htaccess查找
www.test.mydomain.com
,此外,您没有在测试之前逃逸
如果你改成这个,你应该没问题
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.mydomain\.com$
RewriteRule ^(.*)$ http://192.97.XX.XX/Hello [R=301,L]
现在说:
- 当主机以test.mydomain.com开始时(这就是
^
的意思)
- 将其重定向到,并使其成为永久重定向(301部分,以便Google等可以更新其索引)
NB我也对最后一行做了相当大的修改您可以在测试域的文档根中使用此规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?test\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://192.97.XX.XX/Hello/$1 [L,R]