Search code examples
apache.htaccesshttp-redirect

We neeed apache .htaccess redirect per languages url


We are abandoning the management of some languages ​​on our site. We would like to perform a 301 redirect

I need this langeage redirect 301 rule in apache .htaccess:

/es /pt /ru etc..

to /en

and /es/page_path /pt/page_path /ru/page_path etc...

to /en/page_path

Could you please help me?

tks Simone


Solution

  • You can use either of the methods below. If you have other rewrite rules in your .htaccess you probably want to use the rewrite rule, otherwise I'd stick wit hthe simpler alias redirects.

    When testing, start with temporary (302) redirects and then change them to permanent (301) redirects once you know they are working. This prevents your own browser from caching bad redirects which prevents you from testing to see if fixes work.

    Using mod_alias

    Redirect permanent /es /en
    Redirect permanent /pt /en
    Redirect permanent /ru /en
    

    Using mod_rewrite

    RewriteEngine  on
    RewriteRule "^/?(es|pt|ru)(/.*)?$" "/en$2" [L,R=301]