2

I've looked around for the answer to my question but only to be confused even more. I'm hoping somebody can help me...

I need to redirect this URL:

http://www.example.co.uk/ecommerce/cabinets/aluminium_cabinets

To:

http://www.example.co.uk/products/cabinets/?types[]=illuminated-aluminium-cabinets&types[]=non-illuminated-aluminium-cabinets

I'm using mod rewrite in .htaccess

  • 1
    Just to point it out, in terms of SEO this is a (small) step back :) – Martijn Jan 6 '16 at 11:24
  • the square brackets are not URL safe characters. They don't appear to be serving any good purpose and I would recommend removing them. At the very least they should be escaped. – Stephen Ostermiller Jan 6 '16 at 11:34
  • Do you need to redirect or rewrite to URLs like that? – Andrew Lott Jan 6 '16 at 12:17
  • @AndrewLott redirect 301 – Moclin Jan 6 '16 at 15:38
  • @StephenOstermiller Apache/mod_rewrite will automatically escape the square brackets in the case of a redirect. The square brackets are often used with PHP, which will generate an array from the parameters (although more commonly used with POST form submissions). – MrWhite Jan 6 '16 at 15:41
1

No particular trickery is required. Using mod_rewrite in .htaccess:

RewriteEngine On
RewriteRule ^ecommerce/cabinets/aluminium_cabinets$ /products/cabinets/?types[]=illuminated-aluminium-cabinets&types[]=non-illuminated-aluminium-cabinets [R,L]

Apache will escape (percent encode) the square brackets ([ and ]) by default, which are not strictly allowed unencoded in this context in the URL. (This won't affect reading the URL parameters using PHP's $_GET array.)

This is a temporary (302) redirect. To make it permanent, change R to R=301. Alternatively, to make it an internal rewrite, simply remove the R flag.

| improve this answer | |
  • Thanks for the answer but this doesn't work. I actually don't think it's possible. The destination URL is created when a user selects two filters. Your thoughts @w3d ? – Moclin Jan 6 '16 at 15:42
  • Does it do anything? Do you get an error? Why don't you think it's possible?! There's no reason why this redirect shouldn't "work" (providing .htaccess/mod_rewrite is enabled etc.) However, whether it works with your web application and any existing directives is another matter. (Any external redirects need to go at the top of your .htaccess file if you have other directives - the order is important.) – MrWhite Jan 6 '16 at 16:06
  • Thanks for the reply @w3d It redirects to the page but missies off the query string information. I presume it's not possible because this page is only created when a user selects to filters on the page. There's no external redirects. – Moclin Jan 7 '16 at 16:03
  • "There's no external redirects." - The rewrite above is an "external redirect" (so should go at the top of your file). If the query string is missing (in the address bar) then your site must be doing a secondary redirect. If the page doesn't exist then that may very well be the problem. – MrWhite Jan 7 '16 at 16:42
  • thanks @w3dk I think it's because the page doesn't exist unless the user selects filters to create the URL. We are going to redirect to another page that actually exists. – Moclin Jan 11 '16 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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