I am a beginner and I have just hosted my first ever website; the problem I am faced with now is how to make my site visitors access pages on my site even without adding the page extension.
Example: www.example.com/services Instead of www.example.com/services.php
3
Answers
You can use url rewrite to append the extension when one is not specified. OR you could build a routing system to link specific uri to a specific resource (quick example here). The latter introduces a lot of complexity but gives much more control. For example, here is basic pseudo code based on a custom routing system I built:
All requests automatically go to index.php where my router translates the url request into an actual routes to a resource. With the above static route, if a user requests
http://mySite/home/myPage
, the router will respond with the static file at pathwwwroot/path/to/myPage.php
.Another example of a static route:
If a user requests
http://mySite/home
the router will respond with the defaultwwwroot/path/to/index.php
. Further, if they requesthttp://mySite/home/page5
, router will respond with (if exists)wwwroot/path/to/page5.php
.Routing is somewhat of an advanced concept and these are some oversimplified examples but I hope this gets you started.
edit .htaccess file and add the following
and it will be done
This is the usual solution:
But if you want to use
$_SERVER['PATH_INFO'])
to allow:… you need something like: