Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess regex directory to variable

I need to make a 301 redirect for certain URLs from directory to variable.

EXAMPLE:

    http://domain.com/es/stackoverflow --> http://domain.com/stackoverflow?lang=es
    http://domain.com/he/stackoverflow --> http://domain.com/stackoverflow?lang=he

As it is now I have a "directory structure" for each language and it's making seperate URLs for the same page, it just switches the language.

I just want to add the language identifier at the end.

The thing is not every page had those language identifiers after the tld/

Any thoughts?

Thanks for your time.

like image 339
Lost305 Avatar asked Feb 01 '26 15:02

Lost305


1 Answers

You can try:

RedirectMatch 301 ^/([a-z]{2})/(.*)$ /$2?lang=$1
like image 121
Jon Lin Avatar answered Feb 04 '26 05:02

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!