0

Ok now I've seen this used on multiple sites but never actually seen how it is done. How do people host pages under a PHP file?

Example:

http://www.website.com/index.php/about

I've seen examples that show you how to do things like this:

http://www.website.com/?id=4

But that is not what I want to do, I want to do the top one but I have searched all over and so far I can't find anything relating to it. If anyone could help that would be much appreciated and also how would you do the HTACCESS for it to be:

http://www.website.com/about

Any and all help is appreciated thanks in advance!

Dan Alexander
  • 2,004
  • 6
  • 24
  • 34
  • Just Google "friendly urls php htaccess" and you'll have everything you need. – sjagr Feb 07 '15 at 04:13
  • possible duplicate of [How can I create friendly URLs with .htaccess?](http://stackoverflow.com/questions/3033407/how-can-i-create-friendly-urls-with-htaccess) – sjagr Feb 07 '15 at 04:14

1 Answers1

0

Your raw URL needs to be strutured with a querystring like this:

http://www.website.com/index.php?p=about

And your index.php file has to have a handler, something like this:

$page_to_show = filter_input(INPUT_GET, 'p', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW, FILTER_FLAG_STRIP_HIGH);
if ('about' === strtolower($page_to_show)) {
   show_about_page();
} 

Finally, you'll need to be running Apache as your web server, with mod_rewrite installed. You'll need to add this to your .htaccess file:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?p=$1 [L]

This will allow your script to show the about page if a user enters:

http://www.website.com/about
cpilko
  • 11,792
  • 2
  • 31
  • 45