如何修改 .htaccess 文件以仅重定向一个域的 URL,而不重写同一服务器托管的其他域
我在网站上切换了博客软件(MT 到 WordPress),需要将请求重定向到 http://www.domain1/atom .xml 到 http://www.domain1.com/feed/atom。
我使用了一个简单的重定向匹配规则,但意识到它还将请求重定向到另一个站点(domain2),该站点由服务器托管,位于domain1的子目录中,我不希望发生这种情况(其提要仍然是位于 http://www.domain2.com/atom.xml)。
如何使重定向仅发生在domain1 上?
我试图执行以下操作,但没有成功。
RewriteCond %{HTTP_HOST} ^www\.domain1\.com [NC]
RewriteRule ^/atom\.xml$ http://www.domain1.com/feed/atom [L,R=301]
我很接近吗?
谢谢, 富有的
I switched blogging software (MT to WordPress) on a site and need to redirect requests to http://www.domain1/atom.xml to http://www.domain1.com/feed/atom.
I was using a simple Redirectmatch rule, but realized that it was also redirecting requests made to another site (domain2), that is is hosted by the server, in a subdirectory of domain1, which I do not want to happen (its feed is still at http://www.domain2.com/atom.xml).
How do I get the redirect to only occur for domain1?
I was trying to do the following, but it didn't work.
RewriteCond %{HTTP_HOST} ^www\.domain1\.com [NC]
RewriteRule ^/atom\.xml$ http://www.domain1.com/feed/atom [L,R=301]
Am I close?
Thanks,
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您不对domain2进行任何重写,那么快速解决方法是在其根文件夹中创建一个
.htaccess
文件,并通过RewriteEngine off
禁用重写。否则,您使用
RewriteCond
就走在正确的道路上,它应该可以解决问题。您是否尝试在末尾添加$
(RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
) / 任何拼写错误 /www.
与没有www.
?If you don't do any rewriting for domain2 then a quick fix would be to create a
.htaccess
file inside its root folder and disable rewriting withRewriteEngine off
.Otherwise you are on the right path with the
RewriteCond
, it should do the trick. Have you tried adding$
at the end (RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
) / any misspelling /www.
vs nowww.
?我明白了,但我不确定为什么这会起作用。我将 .htaccess 移动为:
我删除了 RewriteRule 中“atom”前面的斜杠。
我认为我应该有斜线,因为我正在尝试重定向 http://www.domain1.com /atom.xml 。
它位于域的根部......
哦,好吧。谁能解释为什么这有效?传递给模式匹配的字符串是否不包含起始斜杠?
谢谢,
富有的
I figured it out, but I'm not sure why exactly this works. I moved my .htaccess to be:
I removed the slash in front of "atom" in the RewriteRule.
I would think I should have the slash, as I'm tyring to redirect http://www.domain1.com/atom.xml .
It's at the root of the domain...
Oh well. Can anyone explain why this works? Is the string passed to the pattern matching not contain the starting slash?
Thanks,
Rich