0

I am trying to create PHP pages with SEO-friendly slugs like so:

www.example.com/italian-foods
www.example.com/de/italienisches-essen
www.example.com/it/cibo-italiano

Links are created with php-i18n and slugify like so:

<?php
    $link = $i18n->getAppliedLang() .'/'. $slugify->slugify(L::menu_italianfoods);
?>

<a class="nav-link" href="<?php echo $link; ?>">
    <?php echo L::menu_italianfoods; ?>
</a>

This allows dynamic creation of the slug in each language based simply on the translated string for menu_italianfoods.

If the links were not slugified, the links would lead to index.php?page=italian-foods where index.php includes the actual file based on $_GET['page'], in this case views/italian-foods.php.

What is the recommended best-practice for "de-slugifying" the URL in this example? I can imagine a script which switches all possible slugs and points to the correct file to include, but I am not sure if this is overly complicated. Is there a better approach?

Fid
  • 462
  • 4
  • 21

0 Answers0