You are here:  » Shorten the URL


Shorten the URL

Submitted by fstore on Sun, 2011-06-19 15:19 in

Hi David
I asked this by an email, but then thought may be useful to write the same question in forum so others could also benefit from your reply.

I have installed the PT under the Joomla installation.

Joomla Installaltion: example.com
PT installation: example.com/shopping/

PHP config: $config_baseHREF = "/shopping/";
htaccess: RewriteBase /shopping/

Search by Mechant gives me the following URL:
http://www.example.com/shopping/merchant/

When I pick a specific merchant i get the following URL:
http://www.example.com/shopping/merchant/Baby-Express/

Question: Is this possible, when I pick a specific merchant, Can I get following URL Instead? (by skipping the /merchant/ part)
http://www.example.com/shopping/Baby-Express/

I am trying to reduce the URL so I get the current page after /shopping/. Your help is appreciated.

Submitted by support on Sun, 2011-06-19 15:30

Hi,

Sure - what you'd need to do is add a catch-all to the end of .htaccess in /shopping/, using RewriteCond to make sure that it doesn't interfere with existing folders. Try adding the following to the end of .htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ search.php?q=merchant:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]

With that in place, you'd need to update the search results link from the merchant index. To do this, look for following code at line 23 of merchants.php

$item["href"] = urlencode(tapestry_hyphenate($product["merchant"]))."/";

...and REPLACE with:

$item["href"] = $config_baseHREF.urlencode(tapestry_hyphenate($product["merchant"]))."/";

...and also the link to the merchant from the prices table. To do this, look for the following code at line 29 of products.php:

$rows[$k]["merchantHREF"] = $config_baseHREF."merchant/".urlencode(tapestry_hyphenate($row["merchant"]))."/";

...and REPLACE with:

$rows[$k]["merchantHREF"] = $config_baseHREF.urlencode(tapestry_hyphenate($row["merchant"]))."/";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2011-06-19 16:18

Thanks David I will try these out.

Now can I also apply some redirect rules so that I can also skip PT folder /shopping/ and I can get everything at ozprice.com.au/merchant-Name OR ozprice.com.au/brand-Name Or ozprice.com.au/Product-Name etc.

will i have to apply these redirect rule to Joomla htaccess file?

thanks, always appreciate your help.

Submitted by support on Sun, 2011-06-19 16:22

Hi,

That would be down to Joomla's .htaccess which, like Wordpress might use clever logic to create flexible permalinks to content and would complicate matters (the main reason I'm concentrating on the plugins of course at the moment) but i'll take a look...

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Mon, 2011-06-20 05:15

David
That's cool.

Actually I just wanted to go 2 level deep in my URL.

Such as the examples below:

Example.com. Joomla site

Example.com/shopping. Pt installation
Example.com/brand-Name
Example.com/merchant-Name
Example.com/product-Name

I am not sure in order to achieve this results, do I only need to update joomla htaccess or also pt htaccess. When you get chance please have a look at this, I appreciate your help.

Submitted by support on Mon, 2011-06-20 07:47

Hi,

Are you happy to keep brand-, merchant- etc. in your URL? E.g.

example.com/brand-Adidas/

That's the key thing and would be far more likely to be straight forward, because CMS scripts like Joomla and Wordpress use general handlers to create permalinks to your posts, so there has to be something in the URL to differentiate a brand / merchant page from a permalink...

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Thu, 2011-06-23 14:17

Hi David
If this is possible then it will be great, how would I achieve this?

I know after the plugin i will get the better solution for URL but in the main-time if i could get something like you suggested would be great.

example.com/brand-Adidas/
example.com/Products-Adidas/
example.com/merchant-Adidas/

to get the above URL, required changes will be different from the one u mentioned above?

Submitted by fstore on Thu, 2011-06-23 14:33

BTW I I did the changes you mention above, i am getting the following URL

Product is shown at 4th level
http://www.example.com/shopping/product/YOYO.html

Brand is shown at 4th level
http://www.ozprice.com.au/shopping/brand/Baby-U/

Merchant is 3 level
http://www.example.com/shopping/FSTORE/

Can I get everything at 3rd level? ideally 2 level deep URL will be perfect, I guess for that I will have to wait for Joomla plugin. but in the main-time kindly suggest me the solution for 3 level deep URL across everything.

Submitted by support on Thu, 2011-06-23 15:29

Hi fstore,

There's a few steps but it can be done!

Firstly, in includes/tapestry.php look for the following code at line 53:

return $config_baseHREF."product/".urlencode(tapestry_hyphenate($product["normalised_name"])).".html";

...and REPLACE with:

return $config_baseHREF.urlencode(tapestry_hyphenate($product["normalised_name"])).".html";

In categories.php look for the following code at line 20:

$item["href"] = urlencode(tapestry_hyphenate($product["category"]))."/";

...and REPLACE with:

$item["href"] = $config_baseHREF.urlencode(tapestry_hyphenate($product["category"]))."/";

In brands.php look for the following code at line 20:

$item["href"] = urlencode(tapestry_hyphenate($product["brand"]))."/";

...and REPLACE with:

$item["href"] = $config_baseHREF.urlencode(tapestry_hyphenate($product["brand"]))."/";

(it looks like your merchants.php is already modified accordingly)

Now, in search.php we need to add an all index search. To do this, look for the following code around line 73:

      case "merchant":
        // pass through to category
      case "category":
        // pass through to brand
      case "brand":

...and REPLACE with:

      case "allindex":
        $where = "(";
        $where .= "merchant = '".database_safe($parts[1])."' OR ";
        $where .= "category = '".database_safe($parts[1])."' OR ";
        $where .= "brand = '".database_safe($parts[1])."'";
        $where .= ") ";
        $sql = "SELECT SQL_CALC_FOUND_ROWS * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE ".$where.$priceWhere." GROUP BY name";
        $orderBySelection = $orderByDefault;
        break;
      case "merchant":
        // pass through to category
      case "category":
        // pass through to brand
      case "brand":

Finally, the replacement .htaccess

RewriteEngine On
RewriteBase /shopping/
RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/$ merchants.php
RewriteRule ^category/$ categories.php
RewriteRule ^brand/$ brands.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ search.php?q=allindex:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*).html$ search.php?q=allindex:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2011-06-26 11:41

Thanks David
It helped keep the URL to third level. But search by "merchant", "category" and "brand" is not working anymore.

When I search by merchant and click on merchant name, search result doesn't bring anything back. and same thing happen when i search by "category or "brand".

After Joomla plugin will I have to undo these custom changes?

Regards
Hassan

Submitted by support on Sun, 2011-06-26 14:06

Hello Hassan,

I just spotted a minor error in the allindex: support from the mod to search.php from this post above, please correct in your search.php file; if you're still not sure if you could email me your modified .htaccess and search.php i'll check it out on my test server for you.

Once using the plugin, front-end changes won't need to be "undone" as only the back-end / database come into play, with the plugin itself directly making queries to the product database.

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2011-06-26 14:58

Now It displays the products when searching by merchant, category and brand but only first page, when i click next page(i.e 2nd page) I get "FSTORE2" (Page no. followed by merchant name) in search box and dont get any product displayed on 2nd page so forth.

Submitted by support on Sun, 2011-06-26 15:12

Hello Hassan,

Ah - the /query/page.html RewriteRule in .htaccess needs to be moved above the others so that it takes priority, otherwise they are caught by the previous rules... Please try:

RewriteEngine On
RewriteBase /shopping/
RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/$ merchants.php
RewriteRule ^category/$ categories.php
RewriteRule ^brand/$ brands.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*).html$ search.php?q=allindex:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ search.php?q=allindex:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2011-06-26 15:27

After updating my .htaccess as per above, I am getting "Internal Server error" so can't display the page at all.

Submitted by support on Sun, 2011-06-26 15:31

Hi Hassan,

There is a last rule [L] tag missing (corrected above), in place of

RewriteRule ^(.*)/(.*).html$ search.php?q=allindex:$1:&page=$2&rewrite=1&%{QUERY_STRING}

try:

RewriteRule ^(.*)/(.*).html$ search.php?q=allindex:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sun, 2011-06-26 15:46

There is an extra [L] at the end of the code..after removing that, its working fine now. thanks

Submitted by fstore on Sat, 2011-07-02 10:03

Hi David
We have shorten the URL (upto 3 level)as per below
www.example.com/shopping/Product-Name
www.example.com/shopping/Category-Name

But I notice my sitemap is not getting indexed by google. Getting "Not Found" and "unavailable" errors at google webmaster.

My sitemap.php is still creating URL as below, this is why my pages are not getting indexed. Any solution?

www.example.com/Shopping/product/product-Name
www.example.com/Shopping/Category/Category-Name

Regards
Hassan

Submitted by support on Sat, 2011-07-02 10:56

Hi Hassan,

Yes - you would need to update sitemap.php to reflect the new product URL structure - easy to do, at line 32 look for the following code...

        $sitemapHREF = "product/".urlencode(str_replace(" ","-",$row["normalised_name"])).".html";

...and REPLACE with:

        $sitemapHREF = urlencode(str_replace(" ","-",$row["normalised_name"]));

That should do the trick!

Cheers,
David.
--
PriceTapestry.com

Submitted by fstore on Sat, 2011-07-02 15:45

Had to add .".html"; in the end.

Worked perfectly. Thx