This question already has an answer here:
I am trying to have my pages accessible with example.com/about
, example.com/contacts
instead of example.com/about.php
& example.com/contact.php
I am not sure how this is done, but I was able to do it by creating link
<a href='site.com/about'> about </a>
And I have my index.php
set as
$URI = $_SERVER['REQUEST_URI'];
switch($URI){
case '/about';
include 'about.php';
break;
case '/contact';
include 'contact.php';
break;
//...
}
Now, asking if this is a good way will have my thread closed as objective question. But I would like to know, how it is done, or more accurately, how everyone does it.
</div>
I use this in .htaccess
/blah goes to /blah.php etc. It's not slower than loading a php page, and then loading in there.
RewriteEngine On
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://WEBSITE.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]