Forum Moderators: phranque
if (!isset($_GET['id'])) {
$group = array();
while ($row = mysqli_fetch_assoc($result)) {
$group[ $row['company-name'] ][] = $row;
}
foreach ($group as $company_name => $models) {
foreach ($models as $model) {
echo "<a href='$model[id]/'>$model[model-abbreviation]</a>";
}
}
}
if (isset($_GET['id'])) {
$top_thumb = "$image_directory_name" . "top.jpg";
echo "<img src='$top_thumb'>";
echo '</br>';
$images = glob($image_directory_name."*_thumb*");
if (!$images) {
echo 'No images to display.';
}
else {
foreach ($images as $image) {
$full = str_replace('thumb','full',$image);
echo '<a href="'.$full.'" target="_blank"><img src="'.$image.'"></a>';
}
} ^products/(.*)/$ /products/index.php?id=$1 <img src='Company Name/Model Name (Model Version)/top.jpg'></br><a href="Company Name/Model Name (Model Version)/A_full.jpg"><img src="Company Name/Model Name (Model Version)/A_thumb.jpg"></a> if ($row['model-version'] == NULL) { $image_directory_name = "/products/$company_name/$model_abbreviation/"; } else $image_directory_name = "/products/$company_name/$model_abbreviation (" . $row['model-version'] . ")/"; RewriteEngine On
^products/(.*)/$ /products/index.php?id=$1 RewriteEngine On
^products/(.*)/$ /products/index.php?id=$1
So this works fine, UNTIL I turn this rewrite rule on.
^products/(.*)/$ /products/index.php?id=$1
www.example.com/products// <img src='Company Name/Model Name (Model Version)/top.jpg'> so I tried adding /products/ to this line, to change my $image_directory_name variable
Hello okgo and welcome to the Forums. It may be possible that your rewrite is having unintended consequences. If you can clear up what the rule is intended to accomplish, there may be hope of limiting it to that task only.
What is this rule supposed to be doing?
RewriteEngine On
^products/(.*)/$ /products/index.php?id=$1
Yes, exactly. But where are the non-top_thumbs getting set?
if (isset($_GET['id'])) {
$id = $_GET['id'];
$get_item_info = mysqli_query($link, "SELECT products.*, company.company-name FROM products INNER JOIN company ON products.company-id=company.id WHERE products.id='$id'");
$row = mysqli_fetch_assoc($get_item_info);
if (!$row) {
echo 'Error';
exit();
}
$company_name = $row['company-name'];
$model_abbreviation = $row['model-abbreviation'];
if ($row['model-version'] == NULL) { $image_directory_name = "/products/$company_name/$model_abbreviation/"; } else $image_directory_name = "/products/$company_name/$model_abbreviation (" . $row['model-version'] . ")/";
} if ($row['model-version'] == NULL) { $image_directory_name = "/products/$company_name/$model_abbreviation/"; } else $image_directory_name = "/products/$company_name/$model_abbreviation (" . $row['model-version'] . ")/"; and if I click on that link in the source, it attempts to find the image at:
The requested URL /products/ID/Company/Product/file1.jpg was not found on this server.
/products/ID/Company/Product/file1.jpg Company/Product/file1.jpg /products/ID/pagename.xtn /products/ID/ RewriteEngine On
^products/(.*)/$ /products/index.php?id=$1
RewriteRule ^products/(.*)/$ /products/index.php?id=$1 [L] is what happens when the browser thinks the current page is
/products/ID/pagename.xtn
and/or
/products/ID/
What do the URLs look like? The part after /products/
It's important to remember that the browser does not know it has been rewritten. So it will interpret any relative links based on where it "thinks" it is.
RewriteRule ^products/all/$ /products/index.php?company=all&sort_style=all [L]
when I go to /products/all/, all products are listed.
RewriteRule ^products/([a-z0-9-]+)$ /products/index.php?product_slug=$1 [L]
when I select a single product, that one products specs are shown.
#RewriteRule ^products/([a-z0-9-]+)/([a-z0-9-]+)$ /products/index.php?company_slug=$1&product_slug=$2 [L]
This is the one I was testing for my new desired 'single product' page
RewriteRule ^products/(.+)/$ /products/index.php?company=$1&sort_style=all [L]
when I go to /products/pick-a-company/ it shows all products from that company only. RewriteRule ^products/([a-z0-9-]+)$ /products/index.php?product_slug=$1 [L] localhost/products/product-name-here (no trailing slash) 'companyname/productname/' RewriteRule ^products/([a-z0-9-]+)/([a-z0-9-]+)$ /products/index.php?company_slug=$1&product_slug=$2 [L]