1
votes

In my eCommerce software I have a variety of product categories which need removing, I want to 301 them to other new categories I have setup.

The standard .htaccess file has the following content:

## File Security
<FilesMatch "\.(htaccess)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

#### Apache directory listing rules ####
DirectoryIndex index.php index.htm index.html
IndexIgnore *

#### Rewrite rules for SEO functionality ####

<IfModule mod_rewrite.c>
  RewriteEngine On

  ######## START v4 SEO URL BACKWARD COMPATIBILITY ########
  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule cat_([0-9]+)(\.[a-z]{3,4})?(.*)$ index.php?_a=category&cat_id=$1&%1 [NC]

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule prod_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=product&product_id=$1&%1 [NC]

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule info_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=document&doc_id=$1&%1 [NC]

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule tell_([0-9]+)(\.[a-z]{3,4})?$ index.php?_a=product&product_id=$1&%1 [NC]

  RewriteCond %{QUERY_STRING} (.*)$
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule _saleItems(\.[a-z]+)?(\?.*)?$ index.php?_a=saleitems&%1 [NC,L]
  ######## END v4 SEO URL BACKWARD COMPATIBILITY ########

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)\.html?$ index.php?seo_path=$1 [L,QSA]

</IfModule>

If I attempt to add the following to the top of the file:

Redirect 301 /shop/oldcat.html http://www.domain.co.uk/newcat.html

When I load the old category URL it shows the old category with the new URL and the following appended to it:

/new-category.html?seo_path=old-category

I have asked around and one of the potential answers is that the Redirect 301 should 'send the headers' immediately... but I don't know what this means...?

1

1 Answers

1
votes

The Redirect directive is part of mod_alias, while the rest of your htaccess file is using mod_rewrite. This means your redirect is getting applied along with the rule which matches (.*)\.html, so 2 things are getting applied to the same request.

In this case, it's best to just stick with mod_rewrite. So near the top of your rules (under RewriteEngine On) add:

RewriteRule ^shop/oldcat\.html$ http://www.domain.co.uk/newcat.html [L,R=301]