Simple MVC mod-rewrite

前端 未结 2 717
既然无缘
既然无缘 2020-12-19 11:28

I\'m not sure how to do a mod-rewrite for a modular MVC structure. What I want to happen is the URL captures:

2条回答
  •  执笔经年
    2020-12-19 11:49

    You could use a PHP function to do that. Quickly, with no default value or error handling:

    list( $controller, $function, $params ) = explode( '/', $uri, 3 );
    $params = explode( '/', $uri );
    

    And in the .htaccess, redirect any non-existing query to your PHP query-handling file:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ mvc.php [L,NS]
    

    Beware to filter your input though, not to include any file, etc.

提交回复
热议问题