Forum Moderators: phranque

Message Too Old, No Replies

Struggling redirecting product.pl?id=fittedcot style urls?

         

fewleh

5:30 pm on Jun 1, 2011 (gmt 0)

10+ Year Member



Hi, I've spent most of the day trawling the internet trying variants of 301 redirects to get this to work.

I'm not sure really where I'm going wrong -

Basically, changed shop over to a new system and need to individually forward each old page to the new one on new site.

There is no structure behind it, so I will do each individually.

Example: http://www.example.co.uk/cgi-bin/product.pl?id=fittedcot

needs to redirect to

http://www.example.co.uk/eczema/dermatherapy

How can I do this? I've got quite close, when I was able to redirect to
http://www.example.co.uk/eczema/dermatherapy?id=fittedcot which is close apart from appending the query string, but even attaching the "?" to end of the url to remove the string (so I read), it wasn't disappearing, and now I've fiddled so much, I can't get it working at all.

Please could someone let me know a line of code that will work for this? I've tried the basic ones:

Redirect 301 /cgi-bin/product.pl?id=fittedcot http://www.example.co.uk/eczema/dermatherapy?

and

RewriteCond %{QUERY_STRING} ^id=fittedcot$
RewriteRule ^product\.pl$ http://www.example.co.uk/eczema/dermatherapy? [R=301,L]

^^^ I thought this would work. But it's not picking it up/doing nothing. I have other 301's working, and have rewriteengine on etc...I'm starting to lose my mind with it...seems simple compared to all the complex dynamic ones I've been reading today! Just can't crack it. I'm sure i'm going wrong with the query string

[edited by: phranque at 11:42 pm (utc) on Jul 14, 2013]
[edit reason] exemplified domain [/edit]

fewleh

5:35 pm on Jun 1, 2011 (gmt 0)

10+ Year Member



I also tried this formation, but it wasn't working properly either -

RewriteRule ^products\.pl?id=fittedcot$ http://www.example.co.uk/eczema/dermatherapy? [R=301,NC,L]

[edited by: phranque at 11:43 pm (utc) on Jul 14, 2013]
[edit reason] exemplified domain [/edit]

fewleh

5:36 pm on Jun 1, 2011 (gmt 0)

10+ Year Member



The last one I posted, works, but appends the query string to my SEF url, which I don't want...how can I stop it doing this?

g1smd

7:41 pm on Jun 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You must not use Redirect or RedirectMatch. You must use RewriteRule.

RewriteRule cannot see query strings so you must use a separate RewriteCond for that.

You added start and end anchors to the query string pattern, so it will work only for exact match without other parameters.

Clear the query string from the redirect target by ending the URL with a question mark.

Yes, you do need a 301 redirect.

If you have many URLs to redirect, you should instead rewrite to a script which then uses an array or a database to look up the new URL; the script then sending the redirect response too.

There was a thread here (in WebmasterWorld Apache forum) with most of the code you will need, only a week or two back.

fewleh

10:04 am on Jun 2, 2011 (gmt 0)

10+ Year Member



This rule below almost works corectly, but adding the "?" at the end of the url doesn't seem to remove the string? It's adding the ?id=fittedcot to the SEF Url...I will try and look back and find the thread you mention - I've only got about 20 urls - 30 urls to do, so not too worried about an array. Thanks for wise words though.

RewriteRule ^products\.pl?id=fittedcot$ http://www.example.co.uk/eczema/dermatherapy?

[edited by: phranque at 11:44 pm (utc) on Jul 14, 2013]
[edit reason] exemplified domain [/edit]

g1smd

11:48 pm on Jun 2, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule cannot see query strings so you must use a separate RewriteCond for that.

fewleh

9:55 am on Jun 6, 2011 (gmt 0)

10+ Year Member



Hi g1smd, thanks for the response - can you give me an example of how I can use the rewritecond in combination with the rewrite rule pls? I'm not sure how I can get it to do it

g1smd

8:58 pm on Jun 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's about 15 000 prior examples in this forum. :)

fewleh

11:02 am on Jun 7, 2011 (gmt 0)

10+ Year Member



Please could you point me in the direction of one that applies? :D go on....you know you want to. Stop being coy.

g1smd

11:06 am on Jun 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's one in your initial post. :)

That ruleset, as posted, only works for exact match parameters. If there are additional parameters, the ruleset will fail.

fewleh

2:19 pm on Jun 7, 2011 (gmt 0)

10+ Year Member



Ok...

So I have loads of urls...all in this format from the old website setup -

/cgi-bin/product.pl?id=hair001
/cgi-bin/product.pl?id=brea001
/cgi-bin/product.pl?id=sal003
/cgi-bin/product.pl?id=lite02
/cgi-bin/product.pl?id=bew003
/cgi-bin/product.pl?id=fitteddoub

You talk of exact match paramters... I feel that what I'm using should work?

I'm trying this for example - but it just doesn't recognise it..

RewriteCond %{QUERY_STRING} ^id=hair001$
RewriteRule ^product\.pl$ http://www.example.co.uk/eczema/dermatherapy? [R=301,L]

Not sure why this won't pick it up? Please can you put me out of my misery :( If this approach won't work, what else can I try? Really do appreciate any guidance you can offer

[edited by: phranque at 11:44 pm (utc) on Jul 14, 2013]
[edit reason] exemplified domain [/edit]

fewleh

2:39 pm on Jun 7, 2011 (gmt 0)

10+ Year Member



I got it working! :)

With this - (remove the ^ and $ )

RewriteCond %{QUERY_STRING} id=hair001
RewriteRule product\.pl http://www.example.co.uk/hair-loss/lasercomb-reduce-hair-loss? [R=301,L]

Thanks for your help

[edited by: phranque at 11:44 pm (utc) on Jul 14, 2013]
[edit reason] exemplified domain [/edit]