This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
using_multiviews_for_pretty_url_routing [2012/09/27 02:21]
Joel Dare
using_multiviews_for_pretty_url_routing [2012/09/27 02:27] (current)
Joel Dare
Line 1: Line 1:
 +====== Using MultiViews for Pretty URL Routing ======
 +I often build small PHP web projects. ​ Typically, I don't want to use a large MVC Framework for the project because it only consists of a few PHP files. ​ But, in many cases, I'd still like Pretty URL's without file extensions.
 +  http://​www.example.com/​post
 +One simple solution is to turn on MultiViews in Apache. ​ You can do this in the httpd.conf file or in the .htaccess file.  MultiViews are setup on a per directory basis. ​ So, you'd put something like the following in your virtual host setup.
 +<​VirtualHost *:80>
 +       ​ServerName example.com
 +       ​DocumentRoot /​httpd/​example/​
 +    <​Directory /​httpd/​example/>​
 +        Options FollowSymLinks MultiViews
 +    </​Directory>​
 +With the MultiViews option turned on, if a file for a particular URL doesn'​t exist, Apache will look for a close match. ​ So, if you have a file called //​post.php//​ apache will find it when you enter a URL with just ///​post//​. ​ No rewrite rules are required.
 +Instead of the mod_rewrite module, MutlViews requires the [[http://​httpd.apache.org/​docs/​2.2/​mod/​mod_negotiation.html|mod_negotiation]] module. ​ I typically find that it's already installed. ​

comments powered by Disqus
using_multiviews_for_pretty_url_routing.txt ยท Last modified: 2012/09/27 02:27 by Joel Dare