Jitendra Vyas Jitendra Vyas - 1 month ago 5
PHP Question

How to make extension-less url for a PHP based site?

Do I have to put every file in a different folder?

like:

about-us/about-us.php
profile/profile.php


etc.

or is there any other automatic solution.

I want to convert

http://sitename.com/about-us/about-us.php


to

http://sitename.com/about-us

Answer

You want pretty URL rewriting.

An Apache .htaccess examples from that article:

  • Pretty URL: /browse/animals-24/cats-76.html

  • Ugly URL: /browse.php?category=24&subcategory=76

  • .htaccess:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^browse/[A-Z0-9_-]+-([0-9]+)/[A-Z0-9_-]+-([0-9]+)\.html$ browse.php?category
    
Comments