.htaccess opencart redirect 301

I just port my site from asp to opencart. In .htaccess, I would like to do some redirects so that my client can use the old link to access

inside .htaccess

redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us redirect 301 /downloads.asp http://www.example.com/downloads 

For contacting us, which work fine, however, for the download URLs, this did not work. when I access http://www.example.com/downloads.asp , it redirects to http://www.example.com/downloads?_route_=downloads.asp and Opencart show that the page was not found. For http://www.example.com/downloads we have set a friendly SEO URL in the backend system.

We have access to

http://www.example.com/information/downloads

http://www.example.com/downloads

but we cannot access with a normal link

http://www.example.com/index.php?route=information/downloads

Next up is my full .htaccess

 # Prevent Direct Access to files <FilesMatch "\.(tpl|ini)"> Order deny,allow Deny from all </FilesMatch> # SEO URL Settings RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us redirect 301 /downloads.asp http://www.example.com/downloads 

============= OTHER TESTS =========================

I checked this on my local host, I found out that this is a great result. However, my problem is still not resolved.

I am running .htaccess from http: // localhost / example and http: // example (virtual directory added)

For http: // localhost / example

 redirect 301 /example/downloads.asp http://localhost/example/downloads/ 

and

For http: // example

 redirect 301 /downloads.asp http://example/downloads/ 

Then I tried to redirect the link to my version in real time, with localhost (http: // example)

 redirect 301 /downloads.asp http://www.example.com/downloads/ 

I refer to http: //example/downloads.asp

The browser redirects me

http://www.example.com/downloads?route=downloads.asp

FAVORITE

In the LIVE version, I did not add a redirection code [VERY SURE FOR THIS]

But in the live version, I get access directly with enter

http://www.example.com/downloads

I'm not sure why the localhost redirect 301 will be released in the live version

http://www.example.com/downloads?route=downloads.asp

Any idea?

+4
source share
3 answers

Solution found: .htaccess redirect 301 working with opencart v1.5.4.1

Extra code needed for ... (and the credits of this fix): https://github.com/opencart/opencart/pull/142 ... replace the contents: - directory / controller / general / seo_url.php - system / library /url.php

Redirect: RewriteRule contacto http: .... com / index.php? Route = information / contact [R = 301, L]

Redirect does not work: redirect 301 contacto http: .... com / index.php? route = information / contact

Verified.

+4
source

Put it in front of the router. Also add $ after .asp and ^ in front.

 # Prevent Direct Access to files <FilesMatch "\.(tpl|ini)"> Order deny,allow Deny from all </FilesMatch> # SEO URL Settings RewriteEngine On redirect 301 ^contact.asp$ http://www.example.com/index.php?route=information/contact_us redirect 301 ^downloads.asp$ http://www.example.com/downloads RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA] 

Why don't you redirect the contact to /information/contact_us instead of index.php?route=information/contact_us ?

+3
source

Can you try "?" at the end of the redirect url if it is not there, for example the 2nd url (it worked for me):

 redirect 301 /contact.asp http://www.example.com/index.php?route=information/contact_us redirect 301 /downloads.asp http://www.example.com/downloads? 
0
source

Source: https://habr.com/ru/post/1347190/


All Articles