Redirect 301 to specific urls

Asked

Viewed 136 times

2

How do I do in htacess redirect 301 ?
But in specific urls, I changed my domain, and migrated the posts for example:
meusite.com.br/article/article name
meusite2.com.br/article/article name

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

  • Try it like this: ErrorDocument 301 http://meusite2.com.br

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 sets a condition to perform the next RewriteRule if it matches. In this case, if the old host meusite.com.br.

    • NC does ignore high/low box.
  • ^artigo(/.*|$) home:
    ^ - string start
    artigo - literal
    (/.*|$) - one / followed by any text, or the end of the string
    the value corresponding to (/.*|$) is captured in $1.

  • http://meusite2.com.br/artigo$1 the new host, with the text captured in condition.

  • Flags:

    • R=301 - redirect 301.
    • L - the current rule should be applied immediately, without considering other rules.
    • NC - does ignore high/low box.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.