You are here:  » URL Rewrite Help


URL Rewrite Help

Submitted by frychiko on Fri, 2007-11-09 16:05 in

Hi David,

I would like to test URL Rewrite. I have Price Tapestry installed on my computer at:

localhost/peter/price (opt/lampp/htdocs/peter/price)

Where do I put the .htaccess file? (For now I put it in the /price directory)

Right now I'm getting this as an example when clicking on a product (Syncmaster 226BW) in product search:

http://localhost/syncmaster-226bw/

instead of what I want:

http://localhost/peter/price/product/syncmaster-226bw/

I tried changing "RewriteBase" to "/peter/price" but nothing updates on the URL when I refresh the browser so I'm thinking the .htaccess file is not even being looked at.

regards,
Peter

Submitted by support on Fri, 2007-11-09 16:10

Hi Peter,

That is correct - .htaccess goes in the /price directory (the same directory as Price Tapestry is installed in).

RewriteBase in this instance should be:

/peter/price/

..but also importantly you must have $config_baseHREF set as follows in config.php

  $config_baseHREF = "/peter/price/";

..and also (of course):

  $config_useRewrite = True;

This should result in product URLs similar to (not quite as in your post):

http://localhost/peter/price/product/syncmaster-226bw.html

Hope this helps,
Cheers,
David.

Submitted by frychiko on Sat, 2007-11-10 02:00

Hmm.. that is exactly as I have it know...

Oh! Now I realise the problem (I think). I have modified pricetapestry so products are pulled from a master product table rather than accessing the products table directly. The URL I have is:

products.php?id=5

This is the id of product syncmaster-226bw.

I'm guessing the .htaccess is not picking up on this because the URL is different than the rule you've originally written, but I don't know how to convert this URL to:

/price/product/syncmaster-226bw.html

I have the name of the product stored in a variable, so I can put that in the url link for the product in the search results. (name = "syncmaster-226bw".

What would be the new rule?

regards,
Peter

Submitted by frychiko on Sat, 2007-11-10 02:27

Sorry David, PLEASE IGNORE MY PREVIOUS REPLY (For now at least).

cheers,
Peter

Submitted by frychiko on Sat, 2007-11-10 09:10

Ok, I managed to get URL rewriting working with my modified setup. Now there's an image problem, no images show up:

For example, in "product.html" I place somewhere:

<img src="images/4.gif" />

This results in no image (of course with full path, image shows), and the source is:

http://localhost/peter/price/product/samsung-226bw/images/4.gif

I guess I need a rewrite rule for images so it's not appended onto current URL... What would this rule be? I've tried various examples from the web, but nothing is working so far.

regards,
Peter

Submitted by support on Sat, 2007-11-10 09:27

Hi Peter,

You don't need a full path for the images, all you need to make is make sure that you use absolute rather than relative URLs.

What you have at the moment is a relative URL, so the browser looks for images/4.gif in the current directory, which if you are using re-write makes the browser think is somewhere deep in your site. To fix it, all you need to is add a leading / to the image src, and that makes the browser look for the image relative to the top level directory of your site, for example:

<img src="/images/4.gif" />

That should sort it!
Cheers,
David.

Submitted by frychiko on Sat, 2007-11-10 09:35

Ok I see.

What if the site is not in the document root? Mine is in /peter/price/
So I guess the following would be the best solution?

$src = $config_baseHREF."images/4.gif";

<img src="<?=$src?>">

cheers,
Peter

Submitted by support on Sun, 2007-11-11 15:41

Hi Peter,

Yes - using $config_baseHREF is a good way to do it. Instead of the above you could use (whilst in HTML mode):

<img src="<?=$config_baseHREF?>images/4.gif">

Cheers,
David.

Submitted by nosferatu on Thu, 2008-10-09 13:55

please please tell me how have you made the path to de product like this http://localhost/syncmaster-226bw/

My product path is http://localhost/product/syncmaster-226bw/

Submitted by support on Thu, 2008-10-09 13:58

Hi,

The details are in this thread:

http://www.pricetapestry.com/node/2003

...make sure to read it all first as there are some complications that you need to be aware of doing this...

Cheers,
David.

Submitted by nosferatu on Thu, 2008-10-09 14:04

Thank you very much

Submitted by Antony on Sun, 2020-06-07 13:34

Hi David,

Hope you're well,

I Need to rewrite URLS so the "shoppinglist" becomes "comparelist" instead. I've used RewriteRules for Brands, and Merchants to customise my site by editing .htaccess and tapestry.php and all went well but I cant get around doing the same thing for the shopping list.

Also, another twick that I need to implement would be to replace the Banner [h2] on reviews.php and products.php to output the product description rather than the product name. (I generate my own feeds using short product descriptions as product names)

Is this possible?

Let me know if you have any questions,

Thanks,

Ant

Submitted by support on Mon, 2020-06-08 07:12

Hi Ant,

There's a single point in the code for generating the Shopping List URL - so if you edit includes/tapestry.php and look for the following code at line 473:

    return $config_baseHREF."shoppinglist.php";

...and REPLACE with:

    return $config_baseHREF."comparelist/";

(or as required)

And then corresponding in .htaccess add the following at the end:

RewriteRule ^comparelist/$ shoppinglist.php

Regarding using the product description in the banner (h2 tag), in products.php and reviews.php locate the following line towards the end of the scripts;

  require("html/banner.php");

...and REPLACE with:

  $banner["h2"] = $product["products"][0]["description"];
  require("html/banner.php");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-06-08 08:36

Thanks David, works like a charm as usual! ...

One last thing then I probably wont bother you again :)

I've been looking into trying to modify the rating stars appearance and I would be particularly interrested replacing the gif stars to fontawsome stars.

I came across this online: https://www.codespeedy.com/star-rating-system-with-php-using-font-awesome-star-icons/

When looking at function tapestry_stars($stars,$imagePostfix) within tapestry.php it feels like I could possibly merge similar conditional lines to return the stars but unfortunately I have not been successful so far.

Would you be okay to look into it? or even just let me know if im on the right track?

Many thank again,

Ant

Submitted by support on Mon, 2020-06-08 09:19

Hi Ant,

In the call to tapestry_stars(); $stars is the rating (1-5) and $postfix is "s" for the small version, used in search results etc, otherwise empty, so what you can do is pass $stars to your custom star_rating() function, and I presume being font based it should follow the current font size in effect so you could use $postfix to form part of a class that defines the size, for example:

  function tapestry_stars($stars,$imagePostfix)
  {
    global $config_baseHREF;
    $html = "<span class='pt_stars".$postfix."'>".star_rating($stars)."</span>";
    return $html;
  }

And then in your html/default.css

.pt_stars {
  font-size: 14px;
}
.pt_starss {
  font-size: 10px;
}

...or as required...

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-06-08 13:10

Hi David,

I've inspired myself from your suggestion and actually decided to go with the following which actually works great but unfortunately excludes the sizing ".$postfix.". See bellow.

Can ".$postfix." be included at all such as:

<i class="fa fa-star-o text-secondary ".$postfix.""></i>

Many thanks,

Ant

  function tapestry_stars($stars)
  {
    if ($stars == 0) {
      return '<small><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i></small>';
    }
    if ($stars == 1) {
      return '<small><i class="fa fa-star text-warning"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i></small>';
    }
    if ($stars == 2) {
      return '<small><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i></small>';
    }
    if ($stars == 3) {
      return '<small><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star-o text-secondary"></i><i class="fa fa-star-o text-secondary"></i></small>';
    }
    if ($stars == 4) {
      return '<small><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star-o text-secondary"></i></small>';
    }
    if ($stars == 5) {
      return '<small><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i><i class="fa fa-star text-warning"></i></small>';
    }
  }

Submitted by support on Mon, 2020-06-08 13:29

Hi Ant,

As $postfix is either empty or just "s", I would combine it with something to make the class through which to set the size, so in the markup you posted e.g.;

<i class="fa fa-star-o text-secondary pt_stars".$postfix.""></i>

(and then pt_stars / pt_starss in the CSS as required...)

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2020-06-08 14:00

Hi David,

That totally makes sence indeed and I'll work on this. Thanks for you're help.

Ant