Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PHP TUTORIALS > FRIENDLY URL'S


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Friendly URL's
By Jaisen Mathai - 2003-10-01 Page:  1 2 3 4

Apache ForceType

First we will have a look at how requests will be handled by Apache. Apache has two directives, which will allow us to send a particular file to the PHP engine for parsing. I use this because I like to leave the .php out of the url (as was in the example we looked at). So if we had a file named "article" with valid PHP code, then we could send this request (http://yoursite.com/article) to the PHP engine for parsing. More so, this request (http://yoursite.com/article/other/info) would also be sent to the PHP engine.

Let's look at the FilesMatch and the Files directives. They are essentially the same, except that FilesMatch allows you to use a regular expression to match the names of files. For the purpose of this tutorial, we will just be using the Files directive.


<Files article>
 
ForceType application/x-httpd-php
</Files>

?>

This will make sure that all requests to http://yoursite.com/article will send the file "article" to the PHP engine for parsing.

Back the truck up! ForceType? What's that? That is the second directive we are going to use to tell Apache to treat this request as if were for a PHP file.

Let's try it! Make a file named .htaccess and put this in it.


<Files article>
 
ForceType application/x-httpd-php
</Files>

?>

Now make a file named article (yes, without an extension) and put this in it.


<?php
 
echo 'This thing works!!<br />';
  echo
'Request_Uri is: '.$_SERVER['REQUEST_URI'].'<br /><br />';
  echo
'This could come in handy!';
?>

?>

Viola! Let's move on to some more PHP code!



View Friendly URL's Discussion

Page:  1 2 3 4 Next Page: A pinch of PHP

Copyright 2003 Jaisen Mathai. All rights reserved.


Copyright 2004-2017 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.