Multiviews support

Discussion in 'Feedback/Feature Requests' started by matt, Nov 20, 2005.

  1. matt

    matt New Member

    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.
  2. mistwang

    mistwang LiteSpeed Staff

    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
    
  3. matt

    matt New Member

    Wow, that worked great.

    Thank you! (And Merry Christmas. :))
  4. matt

    matt New Member

    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 
  5. mistwang

    mistwang LiteSpeed Staff

    There is a typo in the rule I posted, %(DOCUMENT_ROOT} should be %{DOCUMENT_ROOT} , otherwise, that rule will be ignored. :)
  6. mangochutney

    mangochutney New Member

    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]

Share This Page