AbanteCart Community

Shopping Cart Operations => Support => General Support => Topic started by: RD on July 20, 2020, 06:40:33 AM

Title: redirect 301 in .htaccess
Post by: RD on July 20, 2020, 06:40:33 AM
Hi all

I have two product pages I want to redirect traffic from, and send to a new page and have read about using redirect 301 in .htaccess.    From what I can piece together, they suggest the following structure should work –

Redirect 301 /old-product1 https://www.mysite.com/new-product
Redirect 301 /old-product2 https://www.mysite.com/new-product

The problem is I’m not sure “where” to place these lines in my .htaccess.  Are other commands needed before the redirect?

At the moment they are directly after the “RewriteEngine on”.   This is nearly working – if I go to https://www.mysite.com/old-product1, the browser shows the URL for the new page like this  www.mysite.com/new-product?_route_=old-product1   but displays “Product not Found”, however the new product does exist.

Here is the .htaccess file - it’s the standard one  installed with Abantecart (I’ve cut the top and bottom bits to shorten for this post).  I did manage to add a section to force https and www which has been working fine.  Many thanks in advance, Rich.


[. . .  top of standard Abantecart .htaccess file snipped . . . ]

Options +FollowSymlinks

# Prevent Directory listing
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "\.tpl">
Order deny,allow
Deny from all
</FilesMatch>

RewriteEngine on

#### redirect old pages to new -  addedby me  ####
Redirect 301 /soap-step-soap-dish-wall-mounted https://www.modish.co.nz/soap-step
Redirect 301 /soap-step-soap-dish-counter-top https://www.modish.co.nz/soap-step

# Rewrite section for retina high-res images with @2x in the end of filename base on cookie HTTP_IS_RETINA
# To emulate Retina mode on your NON-Retina display, add HTTP_IS_RETINA cookie in your browser
RewriteCond %{HTTP_COOKIE} HTTP_IS_RETINA [NC]
RewriteCond %{REQUEST_FILENAME} !@2x
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)\.(gif|jpg|jpeg|png)$ $1@2x.$2
# if @2x isn't available fulfill the original request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)@2x\.(gif|jpg|jpeg|png)$ $1.$2



#### Force HTTPS://WWW and remove trailing / from files – added by me  ####
# RewriteEngine on
# Remove trailing slash from non-filepath urls
RewriteCond %{REQUEST_URI} /(.+)/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ https://www.modish.co.nz/%1 [R=301,L]

# Include trailing slash on directory
RewriteCond %{REQUEST_URI} !(.+)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)$ https://www.modish.co.nz/$1/ [R=301,L]

# Force HTTPS and WWW
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [OR,NC]
RewriteCond %{https} off 
RewriteRule ^(.*)$ https://www.modish.co.nz/$1 [R=301,L]

#### end of stuff added by me




# SEO URL Settings

[ … rest of standard Abantecart .htaccess file snipped  . . . ]
Title: Re: redirect 301 in .htaccess
Post by: abantecart on July 22, 2020, 09:59:05 PM
www.mysite.com/new-product?_route_=old-product1  is not an AbanteCart structured URL. Possibly you have some other application or configuration on your hosting that conflicts.