views:

152

answers:

4

When I go to some websites I notice that there is no file extension on the page. Actually, this site is a proper example. Anybody know how this is done? :]

+9  A: 

This is generally accomplished with URL Rewriting (link goes to a great introductory tutorial).

In the simplest case, a rewrite rule simply redirects every address by adding ".php" (or whatever other file extension) on the end of the url. So if someone tries to visit http://www.yoursite.com/about-me, they are actually viewing the content coming from the file about-me.php.

Chad Birch
Or they are being redirected to index.php, which is normally what happens when using a framework
AntonioCS
+3  A: 

Aside from URL rewriting, you can also change apache's configuration to support alternative file extensions allowing you to do do something like MyPHPPage.html.

Regards,
Frank

Frank V
+6  A: 

This could also be an MVC framework. (Search here, there are lots for php, a famous one for .NET, and I am sure many frameworks for many language.

This site has a root file, lets call it index.aspx (its not, but go with me) and that file has special code to read more of the URL. Used in combination with URL rewriting as mentioned, that special file takes in what would normally be path information and treats it as variable input.

http://stackoverflow.com/questions/778799/possible-to-remove-extentions-on-php-pages

is something like

http://stackoverflow.com/index.aspx/questions/778799/possible-to-remove-extentions-on-php-pages

With index.aspx being the file that is hidden via URL rewriting.. Questions is a parameter indicating the controller, 778799 being a parameter that and the other text being the final parameter. (That is ignored)

For more see

http://www.asp.net/mvc/

http://codeigniter.com/

http://en.wikipedia.org/wiki/Model-view-controller

MrChrister
+1  A: 

Use mod_rewrite. Just put code like this in a file called .htaccess on your root:

RewriteEngine on
RewriteRule ^([^/\.]+)/?([^/\.]+)/?$ index.php?resource_type=$1&id=$2 [QSA,L]

Notice how $1 and $2 access the two quantities in parenthesized portions of the regular expression. It seems easy to extend the code from here

Tony