Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess opencart redirect 301

I just migrate my site from asp to opencart. In .htaccess I would like to do some redirect so that my customer can use back 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 Contact Us that work perfectly, however, for the downloads url, it didn't work correct. when I access to http://www.example.com/downloads.asp it will redirect to http://www.example.com/downloads?_route_=downloads.asp and Opencart show it is page not found. For the http://www.example.com/downloads we had set SEO friendly URL in the backend system.

We able to access with

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

http://www.example.com/downloads

but we not able to access with normal link

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

The folowing 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

============ANOTHER TESTING========================

I did some testing on this on my localhost I found out it is a quit interesting result. However, my problem still haven't solve.

I run the .htaccess from http://localhost/example and http://example (added virtual directory)

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, redirect to my live version link, from localhost (http://example)

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

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

The browser redirect to me

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

NOTED

In LIVE version, I did not added any redirect code [VERY SURE FOR THIS]

But in Live version, I am to access directly with enter

http://www.example.com/downloads

I am not sure why from localhost redirect 301 to live version will come out

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

Any idea?

like image 785
Shiro Avatar asked Feb 24 '23 14:02

Shiro


1 Answers

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

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

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

Redirect Not Working: redirect 301 contacto http:....com/index.php?route=information/contact

Verified.

like image 91
user1715443 Avatar answered Mar 04 '23 03:03

user1715443