Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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=$1 [QSA,L]

RewriteRule ^/prestashop/index\.php?artikeltyp=([0-9]+)$ /prestashop/category.php?id_category=$1 [L]
RewriteRule ^/index\.php?artikeltyp=([0-9]+)$ /prestashop/category.php?id_category=$1 [L]
RewriteRule ^/prestashop/detail\.php?artikel_id=([0-9]+)$ /prestashop/product.php?id_product=$1 [L]
RewriteRule ^/detail\.php?artikel_id=([0-9]+)$ /prestashop/product.php?id_product=$1 [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 http://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?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

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://%{HTTP_HOST}/prestashop/product.php?id_product=%2 [R=301,L])

share|improve this answer
    
Thank you good sir! It worked after some minor adjustments ( id_product=%2 must be id_product=%1 ). –  iHaveacomputer Aug 10 '11 at 23:55
add comment

Try removing "/prestashop" from your rewrite rules but add

RewriteBase /prestashop

just after:

RewriteEngine on

Also, you can read about RewriteBase here:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.