views:

32

answers:

3

All,

I had a question on hosting.I have Pages that are written in php or JSP and is hosted on a server .And if a user enter say http://x.com in the browser, the main.php or main.asp page will be displayed.My question is there a way to hide the extensions..

Thanks...........

A: 

Provided you are using an apache server, you can do this with url rewriting in .htaccess. See http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

davidosomething
+1  A: 

You want mod_rewrite or one of its IIS equivalents.

Ignacio Vazquez-Abrams
+2  A: 

Option 1 mod_rewrite / ISAPI filter to rewrite

For mod_rewrite on Apache, it is as simple as adding a .htaccess file to the root directory of your website with the following content...

The following rule will direct all URIs in this format:

http://yoursite.com/Content/Page/

to

http://yoursite.com/Page.php

IE the last bit of the URI gets transformed into a PHP file of the same name.

RewriteEngine on
RewriteRule ^Content/([^/\.]+)/?$ $1.php [L,NC,QSA]

Option 2 directory structure

This is where you have a folder structure to represent your website and each folder has an index.php file. For example,

http://yoursite.com/Contact-Us/index.php

In this example, visiting

http://yoursite.com/Contact-Us/ 

gives you the extensionless URI that you are after as the index.php page is shown by default.

I only mention this as it is a solution for a situation where you on shared Windows hosting and cannot add an ISAPI filter.

Sohnee