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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.