Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

flexible url rewriting for custom php cms

  •  05-13-2008, 2:45 AM

    flexible url rewriting for custom php cms

    Hi, I've been working on a custom CMS solution and I'm trying to get generic url matching working in .htaccess.

    This is my attempt.. if the file or directory doesn't exist then rewrite

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ([0-9a-zA-Z_\-]+)/?([^.\/]+)[\.html|\.htm] file.php?input=$1,$2,$3,$4,$5

    It will match /go/ and /go/index.html

    Unfortunately it doesn't really work as much as I'd like

    This is what I want it to match..

    level 1

    / -> file.php?input[]=
    /page.html -> file.php?input[]=page
    /page.htm -> file.php?input[]=page
    /folder -> file.php?input[]=folder
    /folder/ -> file.php?input[]=folder
    /folder.test -> file.php?input[]=folder.test
    /folder.test/ -> file.php?input[]=folder.test

    level 2

    /folder/page -> file.php?input[]=folder&input[]=page
    /folder/page/ -> file.php?input[]=folder&input[]=page
    /folder/site.html -> file.php?input[]=folder&input[]=site
    /folder/site.htm -> file.php?input[]=folder&input[]=site

    level 3

    /folder/page/variable -> file.php?input[]=folder&input[]=page&input[]=variable
    /folder/page/variable/ -> file.php?input[]=folder&input[]=page&input[]=variable
    /folder/page/variable.html -> file.php?input[]=folder&input[]=page&input[]=variable
    /folder/page/variable.htm -> file.php?input[]=folder&input[]=page&input[]=variable

    etc.. I'm not sure how many levels it is possible to do but there would usually be no more than 5

    Any regex geniuses out there ready for a challenge? :)

View Complete Thread