-1

I've tried to search for the best way to handle links on a dynamic website when using "Clean" or "Pretty" URLs, but have not been able to find anything.

I've found a LOT of information on how to use mod_rewrite and try_files, which I've implemented successfully, now my php front controller parses all the parameters on a URL, and it links to the page correctly. No problem here.

The issue I'm having is how to best build all the links on my pages. Currently my links are all in the format eg. "www.site.com?do=post&id=23" which works fine. However I'd like them to display as "www.site.com/post/23" which already also works fine, because of try_files, and how my front controller parses all the parameters from the URL.

However do I now go through all my code and change all the dynamically built links to build in the "www.site.com/post/23" format? It seems like a lot of work, and to be honest I'd like to leave it an "option" to either use Clean or Dirty URLs, similar to how Wordpress allows it as an option in their Admin panel.

Do sites like that keep links in the format "www.site.com?do=post&id=23" and use a rewrite function on all the links when the page is created? So the links show up as Clean when the user sees it?

I'm confused as the best way to handle this, and hope I explained what I'm looking for. I just want to know how best to handle the dynamic links and have it optional to display as clean or dirty url format, for lack of a better word.

Thanks for any help.

Chris S
  • 1
  • 1

1 Answers1

0

That's a very conceitual question...

You could see how Laravel framework router works. You do not need to use it, but you can get ideas there.

The router class is responsible of know how to create a url to some resource, page, action, whatever you want.

So in your view you just call a method that return the url.

Elias Soares
  • 9,884
  • 4
  • 29
  • 59
  • You are absolutely right, it is a very conceptual question. That's why I've been searching for days and have decided to finally just ask. I don't want to have to come back and change everything later once I've built more. I'd rather get the "Best Practice" concept going now and continue to build upon it. So was hoping to get ideas from peoples past experiences. – Chris S Nov 25 '16 at 03:06
  • So what you are suggesting is to build a separate class that returns a formatted url for every url that I feed it. Then if I decide to turn off clean_urls as an option, the class would just return the same url it's fed, or I would just use a condition to skip the class formatting entirely? – Chris S Nov 25 '16 at 03:09