Page 1 of 1

url with-out file extension .php/.html?

Posted: Sun May 13, 2012 10:22 pm
by jayson.ph
Hi All,

i wonder how to make a url with-out file extension .php or html?
example:
instead---> samsung.com/nz/consumer.php
here---> samsung.com/nz/consumer

Re: url with-out file extension .php/.html?

Posted: Mon May 14, 2012 12:12 am
by requinix
A very simple change, if you're using Apache, is to enable MultiViews. In a .htaccess

Code: Select all

Options +MultiViews
That will let you omit the extension from any file type that Apache recognizes: at the very least .php, likely images and .css and .js and many others.

If you don't want that much then you need mod_rewrite.

Code: Select all

RewriteEngine on
# not a file
RewriteRule %{REQUEST_FILENAME} !-f
# not a directory
RewriteRule %{REQUEST_FILENAME} !-d
# is a file if you add a .php extension
RewriteRule %{REQUEST_FILENAME}.php -f
# add the extension and stop
RewriteRule $ .php [L]

Re: url with-out file extension .php/.html?

Posted: Mon May 14, 2012 2:32 am
by Pazuzu156
Or you can use regexp and do it that way.

Code: Select all

RewriteEngine On
RewriteBase /

RewriteRule ^([a-zA-Z0-9]+)+(|\/)$ file.php?page=$1
This is how I did mine.