Redirect with htaccess an old URL to a new one

3

I am trying to redirect an old URL to its new structure via htaccess. For example, instead of www.unawebcualquiera.org/contacto/ to www.unawebcualquiera.org/es/contacto /

Before changing to .htaccess I had this:

RewriteRule ^contacto/ contacto.php [L]

And now to redirect I'm tried with:

RewriteRule ^contacto/ contacto.php [L]
RedirectMatch 301 ^contacto/$ es/contacto/ [L,R=301]

But I returned the following error:

  

An internal error has occurred on the server and could not be   complete your application An internal error has occurred in the   server and your request could not be completed. Or the server is   overloaded or there has been a failure in the execution of a CGI program.

    
asked by JetLagFox 03.02.2018 в 15:09
source

1 answer

2

The 2 rules are colliding. You should put it in the reverse order:

RewriteRule ^contacto/?$ es/contacto/    [NC,R=302,L]
RewriteRule ^es/contacto/?$ contacto.php [NC,L]
  • The first redirects and the request goes with the redirect.
  • A second request (or any request to es/contacto/ ) does not match the first rule, and rewrite contact.php (check if the PHP goes there or in es/contacto.php ).
  • Never use a 301 redirect to test, it is very dangerous because they are strongly cached. Start with a 302 and if you are very sure that it works and that it is not going to be modified in the future, it could be changed to a 301.
answered by 13.03.2018 / 00:27
source