Apache .htaccess从域重定向到另一个域
我可以将模式host.com/*的所有请求重定向到otherhost.com吗/* 例如,对host.com/page1的所有请求都需要重写为otherhost.com/page1 困难的部分是,对host.com本身(主页)的请求不应该被重写 这就是我试图做的Apache .htaccess从域重定向到另一个域,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我可以将模式host.com/*的所有请求重定向到otherhost.com吗/* 例如,对host.com/page1的所有请求都需要重写为otherhost.com/page1 困难的部分是,对host.com本身(主页)的请求不应该被重写 这就是我试图做的 RewriteRule^(.*)$http://otherhost.com/$1[R=301,L] 但不断重写所有请求,包括主页 非常感谢任何帮助您应该添加一些条件: RewriteEngine on RewriteCond %{REQ
RewriteRule^(.*)$http://otherhost.com/$1[R=301,L]
但不断重写所有请求,包括主页
非常感谢任何帮助您应该添加一些条件:
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/
RewriteCond %{REQUEST_URI} !^/index.html
RewriteRule ^(.*)$ http://otherhost.com/$1 [R=301,L]
试试这个:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(/index.html)?$
RewriteRule (.*) http://otherhost.com/$1 [R=301,L]
您可以使用以下重写:
RewriteEngine on
RewriteCond %{HTTP_HOST} =host.com
RewriteCond %{REQUEST_URI} !=/
RewriteRule . http://otherhost.com%{REQUEST_URI} [R=301,NE,L]
RewriteCond%{HTTP\u HOST}=HOST.com
检查主机是否为HOST.com
RewriteCond%{REQUEST\u URI}=/代码>检查请求的页面是否不是索引。(如果这是您所说的“对host.com本身(主页)的请求不应重写”)
R=301
说明重定向时应发送永久移动的HTTP 301
头
NE
声明不应转义特殊字符。(例如,?
转义到%3f
)
这很重要如果不指定此项,许多URL将出错。(例如,/blah.php?id=1
将被重定向到/blah.php%3fid%3d1
,这是错误的。)就是这样!工作完美。塔克斯