abrahamgarcia27 Posted June 19, 2013 Share Posted June 19, 2013 How would i write the php and htaccess for nice looking urls like this? http://forums.phpfreaks.com/forum/13-php-coding-help/ I have this php code function getservices(){ $db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE); $db->connect(); //QUERY ACTIVE COLLECTIONS $sql = "SELECT service_id, name FROM `".TABLE_SERVICE."` ORDER BY sort_order ASC"; $rows = $db->fetch_all_array($sql); foreach($rows as $record){ echo '<li><a href="/services/'.$record['service_id'].'">'.$record['name'].'</a></li>'; } } And the htaccess is as follows RewriteRule ^services/([0-9]+)/?$ index.php?action=services&service_id=$1 [NC,L] #HANDLE SERVICES Quote Link to comment https://forums.phpfreaks.com/topic/279334-nice-looking-urls/ Share on other sites More sharing options...
trq Posted June 19, 2013 Share Posted June 19, 2013 Where exactly are you stuck? What code have you currently got in index.php ? Quote Link to comment https://forums.phpfreaks.com/topic/279334-nice-looking-urls/#findComment-1436764 Share on other sites More sharing options...
abrahamgarcia27 Posted June 19, 2013 Author Share Posted June 19, 2013 well i was just brainstorming what would be the best way to do it. I just got the idea of using implode and explode functions to query just the number, but i do not know if that would be the best way. Quote Link to comment https://forums.phpfreaks.com/topic/279334-nice-looking-urls/#findComment-1436766 Share on other sites More sharing options...
abrahamgarcia27 Posted June 19, 2013 Author Share Posted June 19, 2013 I used str_replace and then used explode to get just the first number, Is this the best way to perform this task? Quote Link to comment https://forums.phpfreaks.com/topic/279334-nice-looking-urls/#findComment-1436767 Share on other sites More sharing options...
trq Posted June 19, 2013 Share Posted June 19, 2013 I used str_replace and then used explode to get just the first number What are you talking about? With the code you have shown, your service_id will show up within $_GET['service_id'] on the index.php page. Quote Link to comment https://forums.phpfreaks.com/topic/279334-nice-looking-urls/#findComment-1436794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.