0

All the examples I see with RewriteRule are something like RewriteRule ^([a-z])$ index.php?example=$1

But I have the following case: I want the

example.com/en/something

to rewrite to

example.com/something?lang=en

And that applies to all things in the place of something. Basically I want to only take the first parameter if it's en or ru and rewrite to the same link but only to pass it as a get parameter

So

example.com/en/something-else/anything

also rewrites to

example.com/something-esle/anything?lang=en

How can I do that ?

UPDATE I tried this RewriteRule ^(en|ru)/(.*)$ $2?lang=$1 but it says that the page is not found (it returns the 404 page from my application not from the server).

Angel Miladinov
  • 1,596
  • 4
  • 20
  • 43
  • Please define what you mean by "rewrite" here? ***Redirect?*** Please see https://stackoverflow.com/a/20563773/476. – deceze Nov 27 '18 at 09:53
  • No, I want when I enter example.com/en/something to be able in the code to do something like `$data['lang'] = $_GET['lang']`, so the server must accept that as example.com/something?lang=en. Also there's the issue: how do I get only the first parameter if it matches *en* or *ru* – Angel Miladinov Nov 27 '18 at 10:01
  • 1
    Does your url `example.com/something-esle/anything?lang=en` work if you type it in browser address bar? – Amit Verma Nov 27 '18 at 13:48

1 Answers1

0

I managed to fix it after all. This is my .htaccess now:

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /avc0135/

#Language
RewriteRule ^(en|ru|bg)/(.*)$ $2?lang=$1
RewriteRule ^(en|ru|bg)$ ?lang=$1
#Language

RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

After a few searches on how exactly does .htaccess works I managed to figure out the RewriteRule, the problem after that was that the #Language block was at the bottom, I moved before everything else and it worked.

Angel Miladinov
  • 1,596
  • 4
  • 20
  • 43