Url re-writing : creating an url that contains id and name

Hi,

When I type url site.com/phone/random-text-string/1 , I get the first phone (id : 1) on the db. When I change the ID to, say, 5, “random-text-string” stays the same, but I want it to be fetched from the db and my htaccess should redirect me to that page automatically.

The desired result is : site.com/phone/selectedphonemodel/phoneid

My current htaccess file is below.

RewriteRule ^phone/([\w-]+)/whatevermodelisselected/([\w-]+)/?$ main/templates/phone.php?phone_model=$1&phone_id=$2

Example : If you change the ID of the url below from 193758 to 193994, sitepoint redirects you to the topic that has the id of 193994.

I want to do the exact same thing for my website.
How can I do it?

This time it isn’t a server config problem, but instead it’s a PHP problem. After you get the phone from the database, then you need to compare that phone’s model name (URL-ified) against the string that’s in the URL. If they’re different, then send a header redirect using the correct model name.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.