Jump to content

.php url rewrite


jad3z

Recommended Posts

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!
Link to comment
https://forums.phpfreaks.com/topic/291569-php-url-rewrite/
Share on other sites

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"]) ) {
Link to comment
https://forums.phpfreaks.com/topic/291569-php-url-rewrite/#findComment-1493310
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.