.htaccess redirect from subfolder to folder level up

Viewed 54

My website's basic URL is https://website.com/catalog - the application is in /catalog folder.

What I'd like to do is to allow users from different countries to access my website with: https://website.com/catalog/de, https://website.com/catalog/fr etc (just 5 or six languages).

For example, when a user fires https://website.com/catalog/fr/abc.php I want him to get https://website.com/catalog/abc.php content while keeping https://website.com/catalog/fr/abc.php in the browsers URL bar.

I've tried putting this code in .htaccess located at website.com/catalog/ but it doesn't work:

RewriteRule ^fr/(.*)$ /$1 [L,NC,R]
1 Answers

Please keep your htaccess Rules file inside catalog folder and have it following way.

RewriteEngine ON
RewriteBase /catalog/
RewriteRule ^(?:en|fr|de)/([\w-]+\.php)/?$ $1 [NC,L]

In first non-capturing group I have kept en|fr|de languages, we can put more languages as per your requirement here too.

Related