Jump to content

Page aliases handled by my CMS code, not .htaccess rewrite rules?


Vojta

Recommended Posts

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

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();
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.