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

flexible url rewriting for custom php cms

Last post 05-13-2008, 11:54 AM by gwizz. 2 replies.
Sort Posts: Previous Next
  •  05-13-2008, 2:45 AM 42161

    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? :)

  •  05-13-2008, 4:18 AM 42169 in reply to 42161

    Re: flexible url rewriting for custom php cms

    RewriteEngine ON
    RewriteCond $1 !-f
    RewriteCond $1 !-d
    RewriteRule (([\w/-]+)(\.html?)?$) /file.php?input=$2 [L]

    and explode("/",$_GET['input']) in file.php 

  •  05-13-2008, 11:54 AM 42187 in reply to 42169

    Re: flexible url rewriting for custom php cms

    thanks muchly I'll give that a go
View as RSS news feed in XML