Dareros Posted September 12, 2014 Share Posted September 12, 2014 Hi; I have succesfully managed to route all the traffic to the file controller.php using this command line of .htaccess : RewriteEngine On RewriteRule (.*) /var/www/html/site/controller.php [L,QSA] Now how to tell the controller.php to process the url that was passed. For example i have tried that: controller.php : <?php include( $_SERVER["REQUEST_URI"] ); ?> but the controller.php didn't do anything i keep getting a blank page when i browse any webpage such as site/index.php so how to tell controller.php to echo the content of the request ? because the user shouldn't notice any change as if there is no controller.php. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/291017-how-to-include-uri-content-after-route-traffic-to-controllerphp/ Share on other sites More sharing options...
requinix Posted September 12, 2014 Share Posted September 12, 2014 You have to look at the REQUEST_URI and decide what to do. It's going to be (the path part of) the URL, not a filename. And it's even going to have the query string in there. Or you can modify your .htaccess to say RewriteEngine On RewriteCond %{REQUEST_FILENAME} !=/var/www/html/site/controller.php RewriteCond %{REQUEST_FILENAME} -f RewriteRule (.*) /var/www/html/site/controller.php?filename=%{REQUEST_FILENAME} [L,QSA]Then $_GET["filename"] will be the originally-requested file. Except now, instead of figuring out what file to show, you have to validate the filename - otherwise I could go to http://www.yoursite.com/controller.php?filename=anything I wantand get the contents of whatever file I choose. Quote Link to comment https://forums.phpfreaks.com/topic/291017-how-to-include-uri-content-after-route-traffic-to-controllerphp/#findComment-1490899 Share on other sites More sharing options...
Dareros Posted September 12, 2014 Author Share Posted September 12, 2014 (edited) Thank you very mush, your idea works perfectly. Just have a little issue i would like you to help me with please. When i move the controller.php file into a sub directory such as ctrl, the paths of all the files become: The controller full path : /var/www/html/site/ctrl/controller.php The .htaccess full path : /var/www/html/site/.htaccess The index.php full path : /var/www/html/site/index.php And this is the content of my controller.php <?php include( $_GET['filename'] ); ?> The issue in this case is that /var/www/html/site/index.php which represent http://www.yoursite.com/index.php render html content okay but the css and javascript files paths contains wrong paths so they don't render for example i get : <link rel="stylesheet" href="/site/ctrl/templates/system/css/system.css" type="text/css" /> instead of <link rel="stylesheet" href="/site/templates/system/css/system.css" type="text/css" /> The same for other css and javascript files so what is the solution in this case because i have no clue ? being in .htaccess or in controller.php. Thank you Edited September 12, 2014 by Dareros Quote Link to comment https://forums.phpfreaks.com/topic/291017-how-to-include-uri-content-after-route-traffic-to-controllerphp/#findComment-1490933 Share on other sites More sharing options...
requinix Posted September 12, 2014 Share Posted September 12, 2014 Depends on whatever is generating those URLs. It's not happening automatically. Quote Link to comment https://forums.phpfreaks.com/topic/291017-how-to-include-uri-content-after-route-traffic-to-controllerphp/#findComment-1490934 Share on other sites More sharing options...
Dareros Posted September 12, 2014 Author Share Posted September 12, 2014 Okay, i am using Joomla. So can i grab the requested page content and do preg_replace all occurences of /ctrl from links. Also is your .htaccess trick will alow passing QUERY_STRING such as a=alpha&b=beta to the controller.php because in your example $_GET['filename'] contain the full path to the requested physical script and so won' contain any query string on it also how does controller.php will process post requests ? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/291017-how-to-include-uri-content-after-route-traffic-to-controllerphp/#findComment-1490935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.