Post by supak111 » Sat Jan 25, 2020 8:21 pm

Is does anyone know who to redirect a certain search directly to a product via htaccess? So say someone searches Blue Ball search would look like this:

example.com/index.php?route=product/search&search=blue%20ball
NOW redirect that to: example.com/blueball

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by DigitCart » Sat Jan 25, 2020 9:02 pm

Hi

Edit this file:

Code: Select all

catalog\controller\product\search.php
Find:

Code: Select all

if (isset($this->request->get['tag'])) {
Add before it:

Code: Select all

if ($search == 'blue ball') {
	$this->response->redirect($this->url->link('product/product', 'product_id=42'));
}
42 is an example of product ID.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by supak111 » Sat Jan 25, 2020 9:14 pm

DELETE that, does work :) thanks

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by supak111 » Sat Jan 25, 2020 9:39 pm

Hey one other nubbie php question, how can I rewrite the code below to send blue ball to any URL even if not on my site?

Code: Select all

if ($search == 'blue ball') {
	$this->response->redirect($this->url->link('product/product', 'product_id=42'));
}
PS i just tired and it works, not sure if its the best or proper way to do it

Code: Select all

header("Location: http://example.com/");

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by letxobnav » Sun Jan 26, 2020 2:20 am

that would be fine, just add exit(); after it to stop the rest of the script.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by paulfeakins » Mon Jan 27, 2020 6:33 pm

DigitCart wrote:
Sat Jan 25, 2020 9:02 pm
Hi

Edit this file:

Code: Select all

catalog\controller\product\search.php
Find:

Code: Select all

if (isset($this->request->get['tag'])) {
Add before it:

Code: Select all

if ($search == 'blue ball') {
	$this->response->redirect($this->url->link('product/product', 'product_id=42'));
}
42 is an example of product ID.
Why would you hardcode it rather than make it dynamic?

And why would you edit core files rather than add this to .htaccess?

Pretty poor code above, I don't suggest anyone does that.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by DigitCart » Mon Jan 27, 2020 6:40 pm

paulfeakins wrote:
Mon Jan 27, 2020 6:33 pm
Why would you hardcode it rather than make it dynamic?

And why would you edit core files rather than add this to .htaccess?

Pretty poor code above, I don't suggest anyone does that.
Hi
Yes, But I only showed the way.
I was not going to explain writing a dynamic extension.

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by paulfeakins » Mon Jan 27, 2020 6:56 pm

DigitCart wrote:
Mon Jan 27, 2020 6:40 pm
Yes, But I only showed the way.
I was not going to explain writing a dynamic extension.
Ok but usually if you provide some hacky code it's best to say so and then at least anyone reading will not think this is a good or recommended way to do it :)

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by straightlight » Mon Jan 27, 2020 8:48 pm

This can be easily achieved by creating a /before event without the need to edit core files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by supak111 » Wed Jan 29, 2020 8:03 pm

I though it would have been better to put it in htaccess but didn't know how to write it. Above code does work but yea I would prefer not to edit core files if possible to avoid later bugs and errors.

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm

Post by straightlight » Wed Jan 29, 2020 9:18 pm

If not with an event, since you require site redirection, either with VQMod or OCMod it can be accomplished so not to alter core files.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by supak111 » Fri Apr 30, 2021 2:26 am

paulfeakins wrote:
Mon Jan 27, 2020 6:33 pm
And why would you edit core files rather than add this to .htaccess?

Pretty poor code above, I don't suggest anyone does that.
Hey paulfeakins how exactly would I use htaccess to redirect a search query to a URL?

Say I want to send search query "mints" to mysite.com/mints, this below works but it isn't perfect.

Code: Select all

RewriteCond %{QUERY_STRING} ^route=product/search&search=mints
RewriteRule ^index\.php$ "/mints" [R=301,L]

~ OC 3.0.3.2 and OCmods only ~


User avatar
Active Member

Posts

Joined
Fri Feb 13, 2015 12:09 pm
Who is online

Users browsing this forum: nonnedelectari and 402 guests