Report this

What is the reason for this report?

How I to do redirect in .htaccess in this way?

Posted on September 10, 2015
Nay

By Nay

How I to do a redirect in .htaccess in this way?

www.domain.com/blog/* --> www.domain2.com/* www.domain.com/blog/ir/* --> www.domain2.com/ir/*



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Add the following to domain.com’s .htaccess:

RedirectMatch 301 ^/blog/(.*)$ http://www.domain2.com/$1

Take a look at the following tutorial:

Heya,

To achieve the redirects you want using .htaccess, you’ll need to use mod_rewrite rules. Here’s how you can set up the redirects:

  1. Redirect www.domain.com/blog/* to www.domain2.com/*:

    This rule will redirect any request that starts with /blog/ to the corresponding path on www.domain2.com.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^blog/(.*)$ https://www.domain2.com/$1 [L,R=301]
  1. Redirect www.domain.com/blog/ir/* to www.domain2.com/ir/*:

This rule is specific to URLs that start with /blog/ir/ and will redirect them to the corresponding path on www.domain2.com/ir/.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^blog/ir/(.*)$ https://www.domain2.com/ir/$1 [L,R=301]

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.