如何将所有 url 重定向到 apache 中的新域,除了一个 [英] How to Redirect All urls to a new domain in apache, except one

查看:30
本文介绍了如何将所有 url 重定向到 apache 中的新域,除了一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个站点上的所有内容重定向到一个新域,除了一个路径.

I need to redirect everything on one site to a new domain, except one path.

所以 domain.com/anything 需要转到 newdomain.com/anything.

So domain.com/anything needs to go to newdomain.com/anything.

但我不希望 domain.com/services/xml 重定向.

But I don't want domain.com/services/xml to redirect.

我尝试了很多条件,但没有任何效果.它总是最终重定向它,或者将它重定向到新域上的其他一些奇怪的路径.

I've tried lots of conditions, but nothing works. It always ends up redirecting it, or redirecting it to some other weird path on the new domain.

这不起作用:

RewriteCond %{REQUEST_URI} !^/services/xml$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

感谢任何帮助.谢谢.

推荐答案

我明白了这一点,感谢我与 Ansari 的对话以及托管公司的一些帮助.问题似乎是 url 被重写为 index.php,然后它被再次重定向.所以:

I figured this out, thanks to my conversation Ansari and some help with the hosting company. The problem seems to be that the the url was being rewritten to index.php, and then it was being redirected again after that. So:

  RewriteCond %{REQUEST_URI} !^/services/xmlrpc
  RewriteCond %{REQUEST_URI} !index\.php$ [NC]
  RewriteRule ^(.*)$ http://www.wikiweightscore.com/$1 [L,R=301]

  RewriteCond %{REQUEST_FILENAME} !-f 
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteCond %{REQUEST_URI} !=/favicon.ico 
  RewriteRule ^(.*)$ index.php?q=$1 [QSA] 

这适用于我想要的确切用例.

This works for the exact use case I was wanting.

这篇关于如何将所有 url 重定向到 apache 中的新域,除了一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆