jad3z Posted October 11, 2014 Share Posted October 11, 2014 (edited) I want to rewrite this url site.come/info.php?country=america&state=colorado&city=denver To site.com/info/america/colorado/denver .htaccess RewriteEngine On RewriteBase / RewriteRule ^info/(.*)/(.*)/(.*)/$ info.php?country=$1&state=$2&city=$3 [L] RewriteRule ^info/(.*)/(.*)/$ info.php?country=$1&state=$2 [L] RewriteRule ^info/(.*)/$ info.php?country=$1 [L] info.php <?php // City info if (isset($_GET["country"], $_GET["state"], $_GET["city"])){ include('tabel.city.php'); // State info } elseif (isset($_GET["country"], $state["provincie"])){ include('tabel.state.php'); //Country info } elseif (isset($_GET["country"])){ include('table.country.php'); // Landing Page } else { include('tabel.general.php'); } ?> I think there is something wrong, but I tried so much options for the last 6 days T.T I hope you guys can help me out, thanks in advance! Edited October 11, 2014 by jad3z Quote Link to comment https://forums.phpfreaks.com/topic/291569-php-url-rewrite/ Share on other sites More sharing options...
requinix Posted October 11, 2014 Share Posted October 11, 2014 You think there's something wrong? Quote Link to comment https://forums.phpfreaks.com/topic/291569-php-url-rewrite/#findComment-1493309 Share on other sites More sharing options...
QuickOldCar Posted October 11, 2014 Share Posted October 11, 2014 RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^info/([^/]+)/([^/]+)/([^/]+)/?$ info.php?country=$1&state=$2&city=$3 [L] RewriteRule ^info/([^/]+)/([^/]+)/?$ info.php?country=$1&state=$2 [L] RewriteRule ^info/([^/]+)/?$ info.php?country=$1 [L] That should work for a rewrite, but your check for $_GET is wrong if (isset($_GET["country"]) && trim( $_GET["country"]) != '') { echo $_GET["country"]."<br />"; } if (isset($_GET["state"]) && trim( $_GET["state"]) != '') { echo $_GET["state"]."<br />"; } if (isset($_GET["city"]) && trim( $_GET["city"]) != '') { echo $_GET["city"]."<br />"; } if wanted to check all 3 would need to do this if (isset($_GET["country"]) && isset($_GET["state"]) && isset($_GET["city"]) ) { Quote Link to comment https://forums.phpfreaks.com/topic/291569-php-url-rewrite/#findComment-1493310 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.