Multiviews support

matt

Active Member
#1
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

LiteSpeed Staff
#2
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:
Code:
RewriteCond %(DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.*)/$    $1.php
 

matt

Active Member
#4
I needed two rules to get this to really work right:

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

RewriteCond %(DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)/$    $1.php
 
#6
Multiviews with PATHINFO

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]
 
Top