Redirecionando rotas antigas com Apache e Nginx
by Ricardo Yasuda on February 22, 2010 22:04
Aqui na Bio Ritmo recentemente migramos o site da SmartFit de PHP para Rails, e com isso muitas páginas que estavam indexadas pelo Google ficaram com endereços diferentes. Pensando no SEO, e para não perder as visitas por causa dessa migração, fizemos um redirecionamento permanente (301) com o Apache, usando .htaccess:
Redirect /atendimento.php http://www.smartfit.com.br/atendimento
Redirect /unidades.php http://www.smartfit.com.br/unidades
Redirect /franquias.php http://www.smartfit.com.br/franchises/new
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=1$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/brasilia? [L,R=301]
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=2$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/morumbi? [L,R=301]
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=3$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/porto-alegre? [L,R=301]
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=4$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/copacabana-i? [L,R=301]
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=5$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/copacabana-ii? [L,R=301]
RewriteCond %{REQUEST_URI} ^/a-smartfit.php$
RewriteCond %{QUERY_STRING} ^idUnidade=6$
RewriteRule ^.*$ http://www.smartfit.com.br/unidades/botafogo? [L,R=301]
Repare que as páginas que tinham parâmetros dinâmicos foram um pouco mais trabalhosas, pois precisamos usar mod_rewrite.
Só que nesta semana migramos o servidor para Nginx, e após muita pesquisa e experimentação, cheguei na seguinte configuração:
location /atendimento.php {
rewrite /atendimento.php http://www.smartfit.com.br/atendimento permanent;
}
location /franquias.php {
rewrite /franquias.php http://www.smartfit.com.br/franchises/new permanent;
}
location /unidades.php {
rewrite /unidades.php http://www.smartfit.com.br/unidades permanent;
}
location /a-smartfit.php {
if ($args ~ idUnidade=1) {
rewrite ^ http://www.smartfit.com.br/unidades/brasilia? permanent;
}
if ($args ~ idUnidade=2) {
rewrite ^ http://www.smartfit.com.br/unidades/morumbi? permanent;
}
if ($args ~ idUnidade=3) {
rewrite ^ http://www.smartfit.com.br/unidades/porto-alegre? permanent;
}
if ($args ~ idUnidade=4) {
rewrite ^ http://www.smartfit.com.br/unidades/copacabana-i? permanent;
}
if ($args ~ idUnidade=5) {
rewrite ^ http://www.smartfit.com.br/unidades/copacabana-ii? permanent;
}
if ($args ~ idUnidade=6) {
rewrite ^ http://www.smartfit.com.br/unidades/botafogo? permanent;
}
}
Achei mais limpo que o Apache, funciona sem problemas, e sem perder page ranking.
You may also like:
blog comments powered by Disqus
