0

I've been hired to re-factor some homemade websites. Those websites are made in the good old fashion way: one page = one php file with header, content, script, footer. Now my client wants to update the layout of all the pages I feel like DRYing a bit the code by creating a clean URL system. Instead of :

example.com/page1.php, example.com/page2.php

I'd like to have:

example.com/page1, example.com/page2

Where the two pages call the same php file just charging the content of the page.

My questions are: 1. how to catch the URL and converts it into parameters? 2. how to avoid the website default behavior to search in directory /page1 or /page2?

Nicolas Hefti
  • 303
  • 2
  • 9
  • possible duplicate of [URL Rewriting](http://stackoverflow.com/questions/556240/url-rewriting) – Daan Jul 31 '14 at 12:28
  • Also note that this may impact indexing in search engines (SEO) – Steve Jul 31 '14 at 12:31
  • Ever heard of `.htaccess` (especially `mod_rewrite`) for `apache` or the config files for `nginx`? You should read about them! They are just amazing! – TiMESPLiNTER Jul 31 '14 at 12:38
  • I think, a better duplicate is this one: http://stackoverflow.com/questions/16388959/url-rewriting-with-php. Thanks for your comments and help. @TiMESPLiNTER I appreciate the direction your pointing but your tone hurts me a bit. – Nicolas Hefti Jul 31 '14 at 13:36

1 Answers1

0

If you are using the Apache web server, you can read-up on Multiviews. While normally used to serve up the same page in different languages, its effect is that whenever you specify a name without an extension, and that name isn't already a folder, then the file with the same name will be served.

For example, you ask for http://localhost/example, and example isn't a folder name, then if example.php exists, it will be served up instead. You just have to make sure you don't have two or more files with the same name and different extensions, or a folder and file with the same name.