PDA

View Full Version : Multiviews support


matt
11-20-2005, 12:35 PM
Apache does this cool thing with multiviews enabled where you can have a file like /about/contact.php and refer to it in a URL like /about/contact/ and it works. This is nice in that you don't have to make directories for everything. I would love a way to do this in Litespeed, either as a built-in feature or a rewrite trick.

mistwang
11-20-2005, 12:47 PM
Yes, you do that with a rewrite rule.
If a URL is ended with a '/', then strip the '/', append '.php', then test the existance of the file with a 'RewriteCond ..."

Something like:
RewriteCond %(DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)/$ $1.php

matt
12-25-2005, 09:14 PM
Wow, that worked great.

Thank you! (And Merry Christmas. :))

matt
12-26-2005, 02:49 PM
I needed two rules to get this to really work right:

# Multiviews
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^(.*)/$ $1/index.php

RewriteCond %(DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)/$ $1.php

mistwang
12-29-2005, 08:50 AM
There is a typo in the rule I posted, %(DOCUMENT_ROOT} should be %{DOCUMENT_ROOT} , otherwise, that rule will be ignored. :-)

mangochutney
05-26-2009, 06:07 PM
If you have a URI scheme like this, utilizing PATHINFO:
/topic/Office/Work -> /topic.php/Office/Work
/update/Office/Work -> /update.php/Office/Work
/topic-> /topic.php


# Multiviews
RewriteEngine On
RewriteCond %{REQUEST_URI} !.+php*
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/?(.*)$ $1.php/$2 [L]