0

I came across many ways to create canonical or friendly urls in php if a project is to be built from core php without using frameworks like laravel or similar.

One approach uses .htaccess. I have an application where I need to make friendly directory structure visible to users. Something like this...

mysite.com/science/light/level1/easy/questions

What is the best and secure way to achieve this that can be reliable for a website with good amount of content.

Vishal Kumar
  • 4,419
  • 1
  • 25
  • 31

1 Answers1

1

I would suggest using something like the following. I've used many something like this in many of my projects.

I'd really suggest using altorouter as it's pretty easy to use and setup.

If you don't want to use Altorouter, then you could use some plain PHP + .htacceess.

RewriteRule ^page/([0-9]+)/([A-Za-z0-9-]+)/?$ index.php?p=page&id=$1

So that then, the url would be something like this:

domain.com/[PAGEID]/how-to-make-money-online-at-home

FluxCoder
  • 1,266
  • 11
  • 22