简体   繁体   中英

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.

So:

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

needs to go to:

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:

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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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