Redirecting of HTTP requests

Asked

Viewed 238 times

4

I have the following problem: I would like to redirect (through .htaccess) the urls below with temporary redirection (HTTP/1.1 302 Moved Temporarily)

Examples:

  • http://www.site.com.br/artigo/0/ for http://www.site.com.br/artigo/1/
  • http://www.site.com.br/artigo/2/ for http://www.site.com.br/artigo/1/
  • http://www.site.com.br/artigo/3/ for http://www.site.com.br/artigo/1/
  • etc..

Pe

2 answers

1

Add to your . htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^/?artigo/[023]$ /artigo/1 [R=302,L,QSA]
</IfModule>

0

You Can Use This Rule:

<IfModule mod_rewrite.c>
RewriteEngine On
#regra de redirecionamento de urls antigas
redirectMatch 302 ^(.*)$ http://www.site.com.br/artigo/1/
</IfModule>

You will redirect all pages to the same place.

Credits for Segio Ronei in Redirect 301 and 302

V2: for only the articles you can change to Regular Expression for ^(article\/*)$

<IfModule mod_rewrite.c>
RewriteEngine On
#regra de redirecionamento de urls antigas
redirectMatch 302 ^(artigo\/*)$ http://www.site.com.br/artigo/1/
</IfModule>

so all Urls that contain http://www.site.com.br/article/ will be redirected.

  • Just one detail: s/302/301

  • In fact the idea was to add only to the articles. This will redirect the entire site.

Browser other questions tagged

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