Vojta Posted December 30, 2010 Share Posted December 30, 2010 Hello, I'm learning how to write simple CMS and I'd like it to support page aliases. So that instead of http://www.myweb.com/?id=123 I could use http://www.myweb.com/some-page for example. I don't want to use rewrite rules in .htaccess but I'd like to do it similarly as Drupal. I understood Drupal redirects 404 page not found error to index.php and then somehow handles it. Can you advise how to do it please? Or is there any tutorial or example available? Thank you in advance! Vojta Quote Link to comment https://forums.phpfreaks.com/topic/223003-page-aliases-handled-by-my-cms-code-not-htaccess-rewrite-rules/ Share on other sites More sharing options...
.josh Posted December 30, 2010 Share Posted December 30, 2010 in general you would do something like this: // dunno how you personally map id numbers to file names..perhaps you query a page name from a db, using the id number, but here's an example array that maps id to page $pages = array (1 => 'a.php', 2 => 'b.php'); $id = (int) $_GET['id']; if (file_exists($pages[$id])) { header('Location: ' . $pages[$id]); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/223003-page-aliases-handled-by-my-cms-code-not-htaccess-rewrite-rules/#findComment-1153051 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.