'Rewriting a URL of a custom page

I've made a page /module/hello/?id_category=123, and I need to make the id_category rewritten to a name such as 123 would = abc.

Is there a way to achieve this without making 1000 manual redirects in the htaccess?

I know this can be done with a RewriteRule [L], but as far as I know you can't ask the database to convert the id to a name and then tell htaccess to rewrite the URL.

Thanks,

Luke



Solution 1:[1]

Use the below function and add id_category as string, stringToNumURL function returns you it's numeric mapping. Then just include your URL content like this.

<?php
//http://mypage.com/module/hello/?id_category=abc
$str_arr = stringToNumURL($_GET['id_category']); //return 123
include_once("http://mypage.com/module/hello/".$str_arr);
function stringToNumURL($url){
    $arr = array('a','b','c');
    $arr_values = array_flip($arr);
    $url = str_split($url);
    $url_to_call="";
    foreach ($url as $value) {
        $url_to_call.=$arr_values[$value]+1;
    }
    return $url_to_call;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RIZI