URL rewrite with parameter to another .htaccess site

0

I would like to write a rule in .htaccess with RewriteRule so that when someone enters the old site, it is redirected to the new site by keeping the requested parameter on the old site.

Old site:

velhosite.com.br/?people=alguem
velhosite.com.br/uma-pagina-qualquer?people=alguem

Redirected to new:

novosite.com.br/?pessoa=alguem
novosite.com.br/uma-pagina-qualquer?pessoa=alguem

Thank you in advance for the help.

    
asked by anonymous 16.11.2015 / 12:27

2 answers

1

For redirection I usually use for 301:

Redirect 301 ^(www.)?velhosite\.com\.br/?people=alguem$  http://novosite.com.br/?pessoa=alguem
Redirect 301 ^(www.)?velhosite\.com\.br/uma-pagina-qualquer?people=alguem$  http://novosite.com.br/uma-pagina-qualquer?pessoa=alguem

But you can point the whole site structure from root to subdomain for example, and from there you make the redirects you need:

RewriteRule ^(.*)?$ http://novosite.com.br/$1 [R=301,L]

You can also make a condition for a particular domain:

RewriteCond %{HTTP_HOST} ^(www.)?velhosite\.com\.br$
RewriteRule ^(/)?$ http://novosite.com.br/novo-layout/ [R=301,L]

For each substitution rule, you put in the order:

rule example: ^pagina.php?a=(.*)&b=([0-9])&c=([a-z])$ , can be represented by: /a/$1/b/$2/c/$3 or /a-$1/b-$2/c-$3 or $1/$2/$3 or $1-$2-$3 or a=$1&b=$2&c=$3

You can also modify the order, for example: /c/$3/b/$2/a/$1 . What makes the rule to be recognized is the url typed in the browser, will be interpreted and trigger the original link (the rule) on the server side.

Redirect 301 ^(www.)?velhosite\.com\.br/?people=(.*)$  http://novosite.com.br/?pessoa=$1
Redirect 301 ^(www.)?velhosite\.com\.br/(.+)?people=(.*)$  http://novosite.com.br/$1?pessoa=$2

See more information on rules in apache documentation .

    
16.11.2015 / 13:29
0

Good afternoon, Müller Nato.

I think you need the Flag QSA, Query String Append. It does nothing more than add the query string, that part of the URL that comes after?, Inclusive, to the end of the url rewritten. For example:? Full = bar & bar = full

To make the query string pass to your rewritten URL, simply add this flag. For example:

old_domain.conf

 RewriteEngine On
 RewriteRule ^(.*)$ http://novosite.com.br$1 [R=301,QSA,L]

R - > Redirect flag, 301 HTTP redirect permanent code.

QSA - > Include the query string in the url rewritten.

L - > Last. This means that if this rule is processed, the following rules will be ignored.

Now that the new domain has already received the rewrite url you rewrite the url you received to match your rules, like this:

new_domain.conf

#?people=alguem
#/?pessoa=alguem
RewriteEngine On
RewriteBase /
RewriteRule ^people=(.*) /?pessoa=$1 [L]

#/uma-pagina-qualquer?people=alguem
#/uma-pagina-qualquer?pessoa=alguem
RewriteRule ^/(.*)?people=(.*) /$1?pessoa=$2 [L]

Source: link

    
19.11.2015 / 23:14