Make 301 redirect in specific urls

2

How do I do in htacess redirect 301? But in specific urls, I changed my domain, and migrated the posts for example:
myite.com.br/artigo/nomedoartigo

Make a 301 redirect only when you have / article /
Ai when people who access the old url to see an article for example, go straight to meusite2.com.br
is it possible?

    
asked by anonymous 16.07.2017 / 18:40

1 answer

0
RewriteEngine on

#Somente se for o host antigo...
RewriteCond %{HTTP_HOST}    ^meusite\.com\.br$ [NC]
#... redirecionar só quando tiver artigo/
RewriteRule ^artigo(/.*|$)  http://meusite2.com.br/artigo$1 [R=301,L,NC]

Explanation:

  • RewriteCond defines a condition to execute the next RewriteRule if it matches. In this case, if the old host meusite.com.br .

    • NC causes it to ignore high / low box.
  • ^artigo(/.*|$) - start of string
    ^ - literal
    artigo - a (/.*|$) followed by any text, or end of string Home the value corresponding to / is captured in (/.*|$) .

  • $1 new host, with text captured in condition.

  • Flags:

    • http://meusite2.com.br/artigo$1 - redirect 301.
    • R=301 - the current rule should be applied immediately, without considering other rules.
    • L - causes it to ignore high / low box.
20.07.2017 / 09:26