0

Hello guys I am having issues with one of my sites. Today I deiced to change all my urls to something more presentable. The issue I am having now how to get rid of the spaces. Here is how the link looks right now "http://website.com/repair/iphone%205s"

here is my .htaccess

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^([a-z]+)\/?$ $1.php [NC,L]
RewriteRule ^smartphone/([a-z]+)/?$ devices.php?d=$1 [L]
RewriteRule ^tablet/([a-z]+)/?$ tablet.php?d=$1 [L]
RewriteRule ^repair/([0-9a-zA-Z_\s]+)/?$ repair.php?m=$1 [L]
RewriteRule ^repair/tablet/([0-9a-zA-Z_\s]+)/?$ repairtablet.php?m=$1 [L]
RewriteRule ^repair/ipod/([0-9a-zA-Z_\s]+)/?$ repairipod.php?m=$1 [L]
</IfModule>

The url are build using the model name of each phone I have in my database and they contain spaces so for example iPhone 5s will have the url of "repair/iphone%205s" Here is my php code where I use a _GET statement to return all the repairs for that specif model.

<?php
        $model = mysqli_escape_string($con, $_GET['m']);
        $modelName = mysqli_query($con,"SELECT
        d.id AS 'DeviceID',
        d.model AS 'Model',
        r.id AS 'RepairID',
        r.repair AS 'Repair',
        r.price AS 'Price',
        r.desc AS 'Desc',
        r.active AS 'Active',
        r.img AS 'IMG'
        FROM `tablets` AS d
        LEFT JOIN `tabletrepair` AS r ON
        (d.`id` = r.`pid`)
        WHERE d.`model` =  '$model'
        AND r.`active` = 1 
        ");
    while($row = mysqli_fetch_array($modelName))
    {
          echo $row[Model];
              echo $row[Desc];
              echo $row[Price];
              echo $row[IMG];



    }

    ?>

I would like to replace "http://website.com/repair/iphone%205s" to "http://website.com/repair/iphone_5s"

Thanks any help would be gladly appreciated.

st0rm
  • 29
  • 6

1 Answers1

0

When you create WHERE clause, based on $_GET['m'] value, you can replace all spaces by underscore using str_replace, additionally (i'm not sure if it is necessary) you should decode url (it $_GET['m'] contains %20 instead ' '). Also don't remember about mysql escape or switch to PDO, or other high level database operational library.

$model = str_replace(" ","_",rawurldecode($_GET['m']));

References

  1. http://www.php.net/manual/en/function.rawurldecode.php
  2. http://pl1.php.net/manual/en/function.str-replace.php
Mateusz Odelga
  • 354
  • 2
  • 7
  • Thank you that fixed my issue and yes I will be switching everything to PDO really soon. Thank you again for your help. – st0rm Jun 17 '14 at 22:24