[英]htaccess redirect with full url
是否可以使用htaccess从一个域重定向到另一个域?
RewriteRule http://www.google.com/old-route http://www.google.com/new-route [R=301,L]
RewriteRule https://www.google.com/old-route https://www.google.com/new-route [R=301,L]
如果没有,您将如何在一个项目上重定向多个域?
这可以通过使用rewriteConditions来实现: https ://wiki.apache.org/httpd/RewriteCond
有点像:
RewriteCond %{HTTP_HOST} ^site1
RewriteRule ^old-route$ https://www.site1alt.com/new-route [R=301,L]
对于一个域使用。
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.google\.com/old-route$ [NC]
RewriteRule ^(.*)$ http://www.google.com/new-route [R=301,L]
要重定向所有内容,您可以使用此功能。
Redirect 301 / http://www.google.com/new-route
给定https://www.example.com/foobar ,其他答案中使用的单个%{HTTP_HOST}
仅查找www.example.com
,而不考虑以下路径。 所以这些答案对我不起作用。 也许在Apache版本中有些变化。 对我%{HTTP_HOST}
是连接要检查的%{HTTP_HOST}
和%{REQUEST_URI}
。
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.example\.com/foo\.html$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.example\.com/bar\.html$ [NC]
RewriteRule ^(.*)$ https://www.example.com/foobar [R=301,L]
查看这个很好的Mod_Rewrite变量Cheatsheet ,了解许多可用的mod_rewrite变量的概述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.