php - .htaccess not redirecting successfully for pretty url's -


my .htaccess follows:

options +followsymlinks rewriteengine on  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f  rewriterule ^(.*)$ ./backend-scripts/url_parser.php 

and then, handling url redirect file url_parser.php follows.

<?php  // open file , contents in string format. $string = file_get_contents("../json/site_map.json");  // decode json string associative array. $jsonarray = json_decode($string, true);  // add trailing slash uri if not there. $requesturi = $_server['request_uri']; $requesturi .= $requesturi[ strlen($requesturi) - 1 ] == "/" ? "" : "/";  // split url @ slashes. $uriarray = explode('/', $requesturi);  // select last piece of exploded array key. $urikey = $uriarray[count($uriarray)-2];  // lookup key in sitemap // retrieve absolute file url. $abspath = $jsonarray[$urikey];  // reformulate url. $path = "../$abspath";  // include actual page. include($path);  ?> 

in order test php code, replaced

$requesturi = $_server['request_uri']; 

by following:

$requesturi = "/welcome"; 

and worked perfectly. i'm pretty sure there wrong inside .htaccess file. how can change that?

change:

rewriterule ^(.*)$ ./backend-scripts/url_parser.php 

to

rewriterule ^(.*)$ ./backend-scripts/url_parser.php?url=$1 

then change $requesturi = $_server['request_uri']; to:

$requesturi = (!empty($_get['url']))     ? $_get['url']     : ''; // no url supplied 

warning: not pass user supplied values include(). make sure paths checked against proper whitelist, otherwise malicious user can hijack server.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -