URL customisation rewrite? www.url.co.uk/?brand=branda

The rewrite rule doesn't seem to be working either - am I right in thinking that the first part of the rule should be the new pretty link I want and the second part of the rule is the original link?
 
hmm not seeming to have much luck with this .htaccess I've tried it in the sites root as well as in /a/ - do some servers have rules blocking htaccess modifications like this or am I missing something easy?

could I try it with a full url for testing ?
 
The default logo doesn't appear to be displaying (the set ones work fine) - anyway to troubleshoot this? does the echo $logo_to_use; code cover the default logo if its not been specified? it looks like it does but unsure to why it isnt


<?php

$known_logos = array (
'a' => '<div id="a"></div>',
'b' => '<div id="b"></div>');

$default_logo = $default_logos['<div id="a"></div>'];

$logo_to_use = isset($_GET['brand']) && isset($known_logos[$_GET['brand']])
? $known_logos[$_GET['brand']]
: $default_logo;

echo $logo_to_use;
?>
 
you need to understand what it is the code is doing.

$known_logos is a hash (aka Dictionary) of values indexed by their key. In PHP this association between key and value is denoted by the "=>" symbol. The key is to the left of the symbol, the value to the right.

So:
Code:
$known_logos = array (
  'a' => '<div id="a"></div>',
  'b' => '<div id="b"></div>',
);
Has the keys 'a' and 'b'.

To access a value in a hash, you use the key - not the value. So you should be accessing it as:
Code:
$default_logo = $known_logos['a'];
and not as you have there.
 
P.S. I've been deliberately ignoring it until now, but you can avoid a lot of unnecessary code if all you are doing is using the "brand" value to be the ID of the div.

PHP:
$recognised_brands = array(
  "a",
  "b",
  // etc
);

$default_brand = $recognised_brands[0]; // use first from list arbitrarily.

$brand_to_use = isset($_GET['brand']) && in_array($_GET['brand'], $recognised_brands)
  ? $_GET['brand']
  : $default_brand;

echo '<div id="' . $brand_to_use . '"></div>';
 
perfect I had $known_logos not $default_logos in there at first causing the original problem - thanks for explaining the different code structures - very helpful indeed :)
 
More help - sorry! - I'd like to add another query for eg:

index.php?brand=a&video=blue

I started tweaking the code above but it got me wondering when it comes to the echo to draw the information at the moment it places in brand to use from the list above it..

however from the list above I'd like it to put in quite a chunk of code (a heading, paragraphs, divs, video file). which is specific to the video parameter chosen.

to keep it clean is it best to write a few rules (1 to replace the div heading text) (1 to replace the video variable ie var videoID = 9;) (one to replace the paragraph div with new text) and one to replace a second paragraph div)

Or would it be best to just have all of that code in one big chunk to go in depending on video= option?

I'm not sure how to reference say video=blue and then tell it where the mass of code it to put in as the original code will just place in the name from the array above?

Is that too confusing ?
 
sorry my last post is a bit of a mess - just to clarify i'm asking:

1, whats the best way to list a second array such as video=blue that will then draw a mass of code around 60 lines. as at the moment the only way I can see and find is that it replaces the name from the array list such as $video_to_use which doesn't work in this situation

2, and if what I'm suggesting is too messy - whats a neater option to reference the same array ie video=blue and out put a different piece of code depending on where I want it ie video var=9 in one place and draw a div header in another place off the same reference (ie it knows what brand and video it is so can input the correct text for that)
 
Thanks its using PHP

(You'd probably gathered I'm not a coder)

So how does the URL command then talk to the stylesheet to tell it that it wants a different brand logo? does it replace a div name on the page to do this?

Thanks

For PHP, I wrote a basic seo friendly url guide ages ago. Includes doing the actual rewrites and using them on a normal page. Might be a good place to start?
 
Back
Top Bottom