: Having trouble redirecting old product sites and categories to new pages I recently upgraded a shopsystem to prestashop and imported the previous products (~1200), and I managed to keep the old
I recently upgraded a shopsystem to prestashop and imported the previous products (~1200), and I managed to keep the old category_id and product_id. I'm trying to set up those 2 rules to redirect all my old incoming links to the new page, however for some reason they always end up on the 404 page instead.
So my old link was
detail.php?artikel_id=123
and now this product became
product.php?id_product=123
here is my .htaccess:
<IfModule mod_rewrite.c>
# URL rewriting module activation
RewriteEngine on
# URL rewriting rules
RewriteRule ^api/?(.*)$ /prestashop/webservice/dispatcher.php?url= [QSA,L]
RewriteRule ^/prestashop/index.php?artikeltyp=([0-9]+)$ /prestashop/category.php?id_category= [L]
RewriteRule ^/index.php?artikeltyp=([0-9]+)$ /prestashop/category.php?id_category= [L]
RewriteRule ^/prestashop/detail.php?artikel_id=([0-9]+)$ /prestashop/product.php?id_product= [L]
RewriteRule ^/detail.php?artikel_id=([0-9]+)$ /prestashop/product.php?id_product= [L]
</IfModule>
# Catch 404 errors
ErrorDocument 404 /prestashop/404.php
Note that this is my test installation at my laptop, and the new shop is currently set up under "http://localhost/prestashop/". I tried it with and without the /prestashop/ in the rules, no effect. My .htaccess is in localhost/prestashop/.htaccess.
Any idea of what I do wrong here? Did I escape it correct? How can I find out where it actually tries to redirect to me before i get the 404?
More posts by @Hamaas447
2 Comments
Sorted by latest first Latest Oldest Best
The common mistake that a lot of people do is trying to match whole URL including query string. The reality is: when matching URL, the pattern get applied to path part of it and query string has to be matched separately.
In other words -- RewriteRule cannot be used to match query string directly -- only with help of RewriteCond.
Considering the aforementioned the rule to redirect detail.php?artikel_id=123 to product.php?id_product=123 should be:
RewriteCond %{QUERY_STRING} (^|&)?artikel_id=(d+)(&|$)
RewriteRule ^detail.php$ /prestashop/product.php?id_product=%2 [R=301,L]
This will do 301 Permanent Redirect -- it will tell search engine and ordinary user that from now on this new URL should be used instead of old one (plus helping with duplicate content issue from search engine point of view when the same content is accessible by 2 different URLs: old one and new one).
If you do not want 301 redirect for some reason, then just remove R=301, part.
Considering that this .htaccess is located in /prestashop/ folder, the rule may need some slight tweaking (like providing full URL in RewriteRule target, e.g. RewriteRule ^detail.php$ %{HTTP_HOST}/prestashop/product.php?id_product=%2 [R=301,L])
Try removing "/prestashop" from your rewrite rules but add
RewriteBase /prestashop
just after:
RewriteEngine on
Also, you can read about RewriteBase here:
httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.