在 Apache 301 重定向中设置主机和路径
我需要将 http://oldsite.com/some/content
重定向到 .htaccess 中的 http://newsite.com/some/content
,但仅限该页面(好吧,两页,有相同的想法)。
据我所知,301 重定向在第一个参数中不采用主机,仅采用路径,并且
Redirect 301 /some/content http://newsite/some/content
不会起作用,因为 oldsite.com 是 newsite.com 的服务器别名(可能不理想,但那部分不在我的控制范围内),并且上面的规则似乎导致了重定向循环。
实现这一目标的最佳方法是什么?我无法使用 PHP 解决方案,因为重定向需要在同一个 .htaccess 中的另一个规则之前执行。
I need to redirect http://oldsite.com/some/content
to http://newsite.com/some/content
in .htaccess, but only that page (well, two pages, with the same idea).
From what I can see, 301 redirects don't take the host, only the path, in the first parameter, and
Redirect 301 /some/content http://newsite/some/content
isn't going to work, as oldsite.com is a ServerAlias of newsite.com (maybe not ideal, but that part is out of my hands), and it seems the rule above leads to a redirect loop.
What's the best way to accomplish this? I can't use a PHP solution as the redirect needs to execute before another rule further down in the same .htaccess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置一个环境变量来标识站点,例如:
... 并使用 mod_rewrite 执行条件重定向:
You can set an env variable to identify the site, e.g.:
... and use mod_rewrite to perform a conditional redirection: