我要重定向
www.example.com/forum或example.com/forum
至
www.example.ir/forum使用htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.ir/forum$ [OR]
RewriteCond %{HTTP_HOST} ^example.com/forum$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com/forum$
RewriteRule (.*) http://www.example.ir/forum$1 [R=301,L] 我没能做到这一点,而且我总是:
www.example.irforum (没有斜杠/),它是死链接。
发布于 2016-05-10 17:09:42
您发布的代码不可能重定向到www.example.irforum (没有斜杠)。实际上,您发布的代码不会做任何事情(因为所有条件都不匹配)。如果您正在看到重定向,那么它可能是以前缓存的(错误的)重定向。
假设example.com和example.ir指向相同的位置,那么在.htaccess文件中尝试以下操作:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^forum(.*) http://www.example.ir/forum$1 [R=302,L]上述规则的处理方式如下:
RewriteRule模式^forum(.*)匹配?如果是,那就继续..。HTTP_HOST服务器变量是否与CondPattern匹配。即。Host头是www.example.com还是example.com?如果是,那就继续..。http://www.example.ir/forum$1 --这是RewriteRule替换。$1指的是RewriteRule模式中捕获的组(第一个括号子模式)。任何与(.*)相匹配的。如果example.com和example.ir指向不同的服务器,则不需要RewriteCond指令。
使用302 (临时)重定向进行测试,直到确定其工作正常为止,然后更改为301 (永久)。或者,禁用浏览器缓存进行测试。
HTTP_HOST变量只包含header。例如:example.com。这不包含路径信息。使用RewriteRule模式来匹配URL路径。
https://stackoverflow.com/questions/37144660
复制相似问题