简体   繁体   English

如果域匹配,则使用.htaccess从一个文件夹重定向到另一个文件夹

[英]Using .htaccess to redirect from one folder to another, if domain matches

I need to rewrite all URLs from one folder to another folder, but only if they are doing a request from a certain domain. 我需要将所有URL从一个文件夹重写到另一个文件夹,但前提是它们正在从某个域发出请求。

So: 所以:

www.example.com/blog/path/to/article www.example.com/blog/path/to/article

needs to go to: 需要去:

www.example.com/new-blog/path/to/article www.example.com/new-blog/path/to/article

But it needs to be conditional to example.com, because if the request comes through for, say: 但这必须以example.com为条件,因为如果请求通过,请说:

www.otherdomain.com/blog/path/to/article www.otherdomain.com/blog/path/to/article

it does not need to redirect to the new folder. 它不需要重定向到新文件夹。

Both the folders "blog" and "new-blog" contain two separate Wordpress installs. 文件夹“ blog”和“ new-blog”都包含两个单独的Wordpress安装。 This is the code I currently have in the root public folder, and what does not work: 这是我当前在根公用文件夹中的代码,什么不起作用:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^blog(.*) /new-blog$1 [L,R]

Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

I was able to get it working with this directive, and actually placed inside the /blog folder: 我能够使它与此指令一起使用,并实际上放在/ blog文件夹中:

RewriteCond %{HTTP_HOST} ^new\.example\.com$ [NC]
RewriteRule (.*) http://new.example.com/our-happy-place/$1 [L,R]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM