I have a website which doesn't use friendly URLs and I would like to change that. My links so far are like this http://www.example.com/?l=EN&m=o36ASkkEVi
, where the l
variable contains the viewing language and the m
contains the viewing category (menu). Because the id of a menu item is unique I didn't have problems so far, even if it was a submenu item. But now that I am trying to change it to Friendly URLs I have the following problem:
Firstly, the friendly title of a menu item is not unique since (in my project at least) there can be multiple submenu items (categories) in different main menu items, with the same title. For example, both menu items Camera
and Mobile Phone
both have a submenu called Instructions
. So my goal is for the final friendly URL being something like http://www.example.com/EN/Mobile-Phone/Instructions
and http://www.example.com/EN/Camera/Instructions
.
Secondly, the "depth" of the menu is not predefined. So there could be limitless subcategories of a category (menu).
In the past for small websites I was using static rewrites of htaccess (one rule for each redirection) but right now, where the articles and categories are uncountable, I cannot do the same. I thought of rewriting the .htaccess file on every article or menu creation and editing to have a rule for each case, but I guess after some point that would make a huge .htaccess. Is that solution legit at all?
My question so is this. How can I make a rule at the .htaccess to always sent me to the index.php
instead of trying to find a website's subfolder when I write http://www.example.com/EN/Camera/Instructions
but with keeping the URL being 'visible' to PHP?
I know after that I can use the explode('/', $_SERVER['REQUEST_URI'])
and achieve my goal by selecting from the database the correct language and article or menu, but I do not or cannot figure out a way on how to do the first part.
Also, is there any way that .htaccess can get me all the items after the http://www.example.com/
in something like an array and pass it as variables to index.php
?