Jump to content

Changing Urls?


scm22ri

Recommended Posts

Hi Everyone,

 

I've partly figured out how to change my URLs but I'm having trouble with fixing the space(%20) that's located in my URL.

 

I've tried using the str_replace function but it's either not working or I'm not doing in correctly.

 

My goal is to turn this URL (first one below this statement) into the URL that's below the first one. I'm having a hard time figuring this out. Any help would be appreciated. Thanks Everyone!

 

(URL that works but it has %20, which is something I don't want)

http://whatsmyowncar...lorida/key west

 

(URL that does not work but I'm attemping to make the above URL look like this one)

http://whatsmyowncar...lorida/key-west

 

My .htaccess code is below as well. Thanks again 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']));
$city = str_replace('%20','-',urldecode($_GET['u']));
// $city = str_replace('','-',urldecode($_GET['u']));
// $city = str_replace('-','','%20','-', 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"];
}
}
}
}
?>

 

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

Link to comment
Share on other sites

Are you saying that if you echo $_GET['u'] you get key%20west? Then just run the urldecode on it. Why do you want to add dashes? If you want to replace spaces dashes either do that after the urldecode (you're doing an empty string '', not a space), or do it before the decode, not after. 

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.