Forum Moderators: phranque

Message Too Old, No Replies

Rewriting with a query string

I'm entering the last round, and Apache is winning...

         

civgroup

2:39 am on Oct 20, 2007 (gmt 0)

10+ Year Member



This should be so simple, but it's going on 6hrs now and I just don't know what else to try.

We're moving from one script to another (same server & domain) and the new script will be residing in the same subfolder as the old one (/downloads).

This is the sort of redirect that we're trying to accomplish:

OLD: http://www.example.com/downloads/?dlid=123
NEW: http://www.example.com/downloads/viewfile/123.html

...and here is the current applicable part of our htaccess file (in the web root):


RewriteCond %{QUERY_STRING} ^dlid=(.*)$
RewriteRule ^downloads/$ http://www.example.com/downloads/viewfile/$1.html? [R=301,L]

This is the output we're getting right now:
http://www.example.com/downloads/viewfile/.html

No matter what I try, I simply cannot get that backreference to pass into the substitution string.

My sanity skipped out hours ago. What am I doing wrong?

marke

4:33 am on Oct 20, 2007 (gmt 0)

10+ Year Member



Maybe try this:

RewriteRule ^downloads/([a-zA-Z0-9])$ http://www.example.com/downloads/viewfile/$1.html? [R=301,L]

civgroup

4:44 am on Oct 20, 2007 (gmt 0)

10+ Year Member



Thanks Marke, but that produced no match at all (the page just loaded with no redirection being attempted).

From my apache manual reading (quite a lot today) I think the issue lies in the fact that RewriteRule does not see the query string at all, which is why I tried to set the proper backreference with RewriteCond. I'm just stumped though at why that backreference isn't being carried forward!

marke

4:58 am on Oct 20, 2007 (gmt 0)

10+ Year Member



How about this:

RewriteRule ^downloads/$ http://www.example.com/downloads/viewfile/%1.html? [R=301,L]

Notice the %1 instead of $1

marke

4:59 am on Oct 20, 2007 (gmt 0)

10+ Year Member



Try it with the RewriteCond statement included.

civgroup

5:05 am on Oct 20, 2007 (gmt 0)

10+ Year Member



Well if you were within 50 miles I'd drive over tonight just to shake your hand. That worked!

I'm off to dig into the apache manual again to determine when %1 is the proper way to call a backreference (rather than the $1 I've read everywhere else).

Thank you again!

marke

5:09 am on Oct 20, 2007 (gmt 0)

10+ Year Member



%1 is passed from RewriteCond. $1 comes from RewriteRule :)

If you can help me figure this out I'd be grateful:

[webmasterworld.com...]