0

Is it possible to rewrite a URL that looks like this as an example -

mydomain.com/?id=123

Lets pretend that 123 is an id of a row in a DB. a column in this row could be my name. I would like to rewrite this URL based on the result in the DB -

mydomain.com/rory

Is this possible?

Thanks

4

3 回答 3

1

You can use RewriteMap for that: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap

Have a look at the answers of the following question: Mod_ReWrite / ReWriteMap a URL using a database lookup script

于 2013-05-13T22:04:50.630 回答
1

If there's a logic which can map an ID of 123 to a name "rory" why don't make a redirect like this one in PHP

$id = $_REQUEST['id'];

$name = getNameByIdFromDB($id);

header('Location: ' . $_SERVER["PHP_SELF"] . '/' . $name, 302);

exit;

(that's an example, not working code!)

于 2013-05-13T22:45:42.683 回答
-2

you cant touch dtb from .htaccess file,

you can manual render rules for all possible combinations, but its bad practise - this should be solved in router of your application

于 2013-05-13T21:57:55.803 回答