php - MVC & RewriteRule isn't working at all -
i have built website homemade mvc structure , pretty urls .htaccess aren't working @ all. have "front controller" (index.php
) @ root of website :
<?php require_once('m/connect_sql.php'); if (!empty($_get['page']) && is_file('c/'.$_get['page'].'.php')) { include 'c/'.$_get['page'].'.php'; } else { include 'c/accueil.php'; } $bdd = null;
c/
controller folder.
example of urls : http://domain.com/?page=restaurants&city=paris&cp=75001
page
parameter controller , &city=paris&cp=75001
post variables.
i have tested simple rewrite rule out of mvc , works well. tried several rewrite rules none working.
here's example url above :
<ifmodule mod_rewrite.c> options +followsymlinks rewriteengine on rewriterule ^(.+/)/([^/.]+)/([^/.]+)/?$ /?page=$1&city=$2&cp=$3 [nc,l] </ifmodule>
i have placed .htaccess
in every folder (root, controller, views), can't it.
edit since response :
here's new controller since entwicklerpages notice security hole. found solution here : http://kkovacs.eu/exploiting-web-development-worst-practices-file-inclusion
if ( isset($_request['page']) , ! is_null($_request['page']) ) { $page = $_request['page']; switch ($page) { case 'restaurant': include('c/restaurant.php'); break; case 'restaurants': include('c/restaurants.php'); break; } } else { include('c/accueil.php'); }
be aware of security hole in implementation! never idea let user decide php files included.
include 'c/'.$_get['page'].'.php';
https://www.owasp.org/index.php/testing_for_local_file_inclusion
also, second idea site. $_server
variable in php have field called path_info
$_server['path_info']
if site called index.php/your/params/and/other/data
you can split '/' , data. may little easier make fancy modrewrite
https://secure.php.net/manual/en/reserved.variables.server.php
i use @ own site: http://www.entwicklerpages.de/startseite.html (german)
Comments
Post a Comment