1

Is it possible to do a custom rewrite to remove the parameters when a user changes language?

For example:

www.website.com/product?___store=ca_fr&___from_store=ca2014_en

Should become:

www.website.com/product

I have read about a bit, but I need to do this both ways (so that there is never a parameter for the store change shown in the URL). Is this possible to do? Is it possible through the Magento admin, or does it need to be a .htaccess rewrite?

1 Answer 1

1

This can be done via htaccess, I actually elaborate on this in a question on server fault, though the question itself concerned rules after the query string manipulation.

This code excerpt removes 2 keys called key1 and key2 (substitute with your chosen keys!) and any value, while retaining the rest of the query string and URL itself :

# Activate Rewrite and set the base to the web path
RewriteEngine On
RewriteBase /

# Remove 'key1' from the Querystring, and remove any resulting double &'s
RewriteCond %{QUERY_STRING} (.*)(?:^|&)key1=(?:[^&]*)((?:&|$).*)     

# %1 = any previous query string, %2 = any following query string   
RewriteCond %1%2 (^|&)([^&].*|$)    

# %1 = matched double & (disgard), %2 = the new query string
# $1 = non greedy match on the URI upto the last /
RewriteRule ^(.*)/$ $1?%2  [DPI,E=querycleaned:1]

#Remove 'key2' from the resulting URI, and remove double & again
RewriteCond %{QUERY_STRING} (.*)(?:^|&)key2=(?:[^&]*)((?:&|$).*)  

# %1 = any previous query string, %2 = any following query string     
RewriteCond %1%2 (^|&)([^&].*|$)    

# %1 = matched double & (disgard), %2 = the new query string
# $1 = non greedy match on the URI upto the last /
RewriteRule ^(.*)/$ $1?%2 [DPI,E=querycleaned:1]

#Process any other rules following the query string update here

#Catchall, if query string cleaned but not previously matched, then redirect to clean string
RewriteCond %{ENV:querycleaned} 1
RewriteRule ^(.*)$ $1 [L,R=301]

You'll need to keep an eye out for subsiquent rules (insert at the comment included) and also note that becasue both query string manipuations are not declared as Last rules, we have to add a simple catchall to rewrite the URL with the new query string in the case of no further matches.

Also note, I set an enviroment variable for the catchall to detect, as we don't want to rewrite if there's been no query string manipulation :)

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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