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!
Edited by jad3z
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.