Jump to content

PHP URL Rewriting / .htaccess question


scm22ri

Recommended Posts

Hi Everyone,

 

I'm trying to append another value onto my URL that I'm dynamically inserting via php syntax, I'm having trouble trying to figure it out.

 

I'm trying to append the a "state" onto my URL.

 

In the below URL is my information where I'm pulling my data

http://whatsmyowncarworth.com/auto/display-information.php

 

In the few URLS below is where I'm getting the "city" and appending it to the URL. (my php syntax is below)

http://whatsmyowncarworth.com/auto/Miami

http://whatsmyowncarworth.com/auto/providence

http://whatsmyowncarworth.com/auto/albany

 

What I'm trying to do is this, I want each URL to have a "state" value so I want the URLS to look like this,

http://whatsmyowncarworth.com/auto/albany/new-york

http://whatsmyowncarworth.com/auto/Miami/florida

http://whatsmyowncarworth.com/auto/providence/rhode-island

 

This is my syntax and below that is my .htaccess code. Any help would be great. Thanks everyone!

 

<?php
include('init.php'); // connection to database

// if city exists...
if (isset($_GET['u'])) {
    // decode and replace hyphen with space
    $city = str_replace('-','',urldecode($_GET['u']));
    
    // if value contains only letters, numbers or spaces...
    if ( preg_match('~^[a-z0-9 ]+$~i',$city) ) {
        // select data from database...
        $data = mysql_query("SELECT State, City FROM cars WHERE City='$city'" );
        if (mysql_num_rows($data) > 0) {
            while ($row = mysql_fetch_assoc($data)) {
                                echo $row["City"]; 
			echo $row["State"];
            }
        }
    }
}
?>

 

>>>>>>>>>>>>>>>>>

 

.htaccess

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /auto/cars.php?u=$1 [NC]

Link to comment
Share on other sites

Hi Thorpe,

 

My mistake. I can sometimes ramble on.

 

My question is this,

 

I want to add the state that's associated with the city in the URL. How would I do that?

 

I want the URLS to look like this. (the below URLS don't work)

http://whatsmyowncarworth.com/auto/albany/new-york

http://whatsmyowncarworth.com/auto/Miami/florida

http://whatsmyowncarworth.com/auto/providence/rhode-island

 

These are currently working.

http://whatsmyowncarworth.com/auto/Miami

http://whatsmyowncarworth.com/auto/providence

http://whatsmyowncarworth.com/auto/albany

 

Thanks

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.