I
I
idkiberlord0772017-08-16 15:59:46
PHP
idkiberlord077, 2017-08-16 15:59:46

How to redirect to OpenCart via php?

There was a problem with rewriting links.
With the command:

$this->response->redirect($this->url->link($redirect_roots,301));
//$redirect_roots наша строка. например " /scanner/brend/hp/"

but it redirects me to index.php?route=/scanner/brend/hp/&301=
If I remove "index.php?route=" everything works fine.
Maybe there will be ideas how to remove this part. Searched on the net. I tried many options - nothing worked.
Thanks for the help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2017-08-16
@idkiberlord077

Though I haven't come across OpenCart. But almost all engines by default throw any links to the main script router (for example, index.php). That's why you get the line index.php?route=/scanner/brend/hp/&301=
Look at the $this->url->link sources, with a high degree of probability you will see the link conversion there so that the link starts with index.php.
But if you feed a ready-made link to the redirect method right away,
then most likely you will get what you need.
I'm almost sure that something like this is implemented in this method:

header('Location: ' . $url);
exit;

This is all to the fact that if all else fails, just write this title without using the OpenCart API.

D
Dmitry, 2021-03-09
@sibweb38

Please tell me - how to make a 301 redirect from site.ru/index.php?route=checkout/success to your successful checkout page? The page will be created in open cart 2.0 - the final url will be site.ru/spasibo
In which file and what should I write?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question