1

I have spent a great many hours trying to find a solution to this and tried many different approches but nothing I have tried has worked so far.

I would like to redirect a URL with query string to another URL that contains the value of that query string.

For example:- http://site.co.uk/module/filecatalogue/downloads?cid=value would redirect to http://site.co.uk/module/filecatalogue/downloads/value

Any help would be greatly appreciated as I am about to go insane.

Thanks :-)

Ade Lewis
  • 57
  • 1
  • 8

1 Answers1

1

You can do that by using the following in your .htaccess file:

RewriteEngine On
RewriteCond %{QUERY_STRING} cid=(.+) [NC]
RewriteRule ^(.*)$ http://site.co.uk/module/filecatalogue/downloads/%1? [R=301,NC,L]

What this does is takes your variable cid= as a condition, if the server detects it in the URL it will move forward to the RewriteRule.

It will rewrite it using a 301 redirect to http://site.co.uk/module/filecatalogue/downloads/anything. Anything representing the variable, which is grabbed using (.+).

We include a ? at the end of the URL in order to stop the original query appearing on the end of the new URL.

Make sure you clear your cache before testing this.

Joe
  • 4,503
  • 4
  • 28
  • 47