cancel
Showing results for 
Search instead for 
Did you mean: 

.ht access redirect with GET data

RobDickson
Grafter
Posts: 633
Thanks: 2
Registered: ‎06-08-2007

.ht access redirect with GET data

I wonder whether anybody here can help me out. I'm sure I'm being stupid, but I just can't figure this one out.
All I want to do is to redirect
www.mydomain.co.uk/link?id=n
to
www.mydomain/link/n
(where n is a number).
I would have thought that something like these two lines would work:
Redirect 301 /old_dir/link.php?id=([0-9]+)$ http://www.mydomain.co.uk/link/$1
RewriteRule ^old_dir/link.php?id=([0-9]+)$ http://www.mydomain.co.uk/link/$1

The only way that I can find to do it is:
Redirect 301 /old_dir/link.php http://www.mydomain.co.uk/linkredirect.php

This passes the ?id data from link.php to linkredirect.php, and then use PHP's Header function to redirect to the page that I want.
Surely there must be an easier way than this. If anybody can help, I'd appreciate it.
PS: Is there another way to stop the forum code from automatically changing URLs into <a> tags, apart from using the CODE tag?
2 REPLIES 2
deepee
Newbie
Posts: 5
Registered: ‎01-01-2008

Re: .ht access redirect with GET data

Thank for your suggestion about bad bot lists.
Er, I'm still going up the learning curve, but a) I recall reading somewhere that redirect isn't the best way to do this (more appropriate for temporarily or permanently moving whole sites, where it has the advantage that search engines record the new addresses) and b) I also recall reading about the use of mod_rewrite to achieve this sort of thing. Amongst other possible options, a line 'Rewrite Engine On' is necessary directly above the RewriteRule(s), though this isn't always included in examples. (I read it as meaning something like, "rewrite on the following conditions:".
As you presumably don't have the string 'id=' in the domain portion of the address, it ought to be straightforward to write a rule that simply strips these 3 characters out before handing on the modifed address; with [NC] or whatever the option is to ignore case. Wikipedia has a list of useful sites at the end of the Rewrite Engine (aka Mod_Rewrite) page.
Of course we don't know for sure whether PN allows the use of mod_rewrite.
Not applicable

Re: .ht access redirect with GET data

Pretty sure it is allowed - I'm sure I've used it in the past for a couple of bits and bobs.