I've got a website which use this style : /index.php?page=45&info=whatever&anotherparam=2

I intend to have pretty hyperlink to transform the prior hyperlink to : /profile/whatever/2

I understand I must use .htAccess and also to redirect everything to index.php. That's fine.

My issue is more within the index.php (Front Controller). How do i build back the $_GET["info"] and $_GET["anotherparam"] to have the ability to continue using all of the existing code which use $_GET[...] within their page?

Must i build back the Enter the header with a few code or must i eliminate all $_GET[...] on every pages by creating my very own array which will parse ever / to and assign something similar to : $myParam["info"] = "whatever" and compared to the page use $myParam[] rather than $_GET[] ?

I'd like to not modify all individuals pages which use $_GET[]


My .htAccess seem like:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ index.php [NC,L]

Exactly what does not exist visit index.php. Since I Have already make use of this structure : /index.php?page=45&info=whatever&anotherparam=2 there is nothing damaged. However I'll use /profile/whatever/2 as well as in the switch situation I'm able to figure out what page to include(..) the main problem is by using all GET parameters. How do you build these to connect all page with $_GET[]?

$path = ... // wherever you get the path $_SERVER[...], etc.
            // eg: /profile/wathever

$segments = split ($path);

$segments_name = Array ('page', 'info', 'anotherparam');
for($i=0;$i  < count ($segments); $i++) {
  $_GET[$segments_name[$i]] = $segments[$i];

with this particular solution you need to always employ exactly the same arguments in the same position

if you do not want you have two solution: - use path like /page/profile/info/wathever - use router system (for your I suggest you to utilize a framework rather than doing the work all by hand)

edit: second solution

$path = ... // wherever you get the path $_SERVER[...], etc.
            // eg: /page/profile/info/wathever
$segments = split ($path);

for($i=0;$i  < count ($segments); $i+=2) {
  $_GET[$segments[$i]] = $segments[$i+1];

Make use of a switch statement rather. Keep in mind to change your .htaccess

switch ($_GET) {
    case "home":
     header('Location: /home/');
    case "customer":
        header('Location: /customer/');
    case "profile":
        header('Location: /profile/');