Forum Moderators: phranque

Message Too Old, No Replies

Help with 301 redirect

? are changing to %3f

         

wsmeyer

6:21 am on Sep 23, 2006 (gmt 0)

10+ Year Member



Is it possible to redirect to a page with GET parameters?

As example, I'm trying to install a 301 redirect from:

www.example.com/old-page.htm?sz=m

to:

www.example.com/new-page.htm?sz=m

It looks right in .htaccess but in the browser it becomes:

www.example.com/new-page.htm%3fsz=m

and returns a 404 error.

William.

jdMorgan

2:12 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, see Apache mod_rewrite [httpd.apache.org], and specifically the query-string checking/back-referencing functions available using the RewriteCond directive, e.g.

RewriteCond %{QUERY_STRING} ^[i]pattern[/i]$

Used in conjunction with a canonical URL and an [R=301,L] flag on the RewriteRule, you can easily redirect URLs with query strings attached.

Jim

wsmeyer

3:56 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



Thanks for the direction, I found the NE flag to not escape the output but what I am trying now:

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteRule ^/some-old-file.htm$ http://www.example.com/new-file.htm?sizePref=2 [R=301,L,NE]

returns a 404 error AND is keeping my FrontPage Extensions from working!

William.

jdMorgan

4:13 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) The example in your first post does not agree at all with the code you posted (Your code does not test the query string).
2) The [NE] flag is not required unless you wish to put a "%" character in the substitution URL.
3) Multiple Options can be combined on one line, i.e.
 Options +Indexes +FollowSymlinks 

4) Is your code placed in httpd.conf or .htaccess?
5) Front page extensions are a completely-different ball game -- See this thread [webmasterworld.com], specifically message #1496336.

Jim

wsmeyer

12:09 am on Sep 30, 2006 (gmt 0)

10+ Year Member



Thanks for the FrontPage tip. I ran into that problem several months ago and spent hours searching the internet but could never find a solution. I can't believe I actually have them working together.

The Apache manual says this about the [NE] flag:

'noescapeŚNE' (no URI escaping of output)
This flag keeps mod_rewrite from applying the usual URI escaping rules to the result of a rewrite. Ordinarily, special characters (such as '%', '$', ';', and so on) will be escaped into their hexcode equivalents ('%25', '%24', and '%3B', respectively); this flag prevents this from being done. This allows percent symbols to appear in the output.

Which sounded exactly like my problem but it turns out I was very close, I just needed to remove the preceeding '/'.

What I ended up with was:

Options +Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteRule ^old-url.htm$ http://www.example.com/new-url.htm?sizePref=2 [R=301,L]

As always, thanks for the help!

William.

[edited by: jdMorgan at 2:54 am (utc) on Oct. 5, 2006]
[edit reason] Example.com [/edit]

g1smd

10:26 pm on Oct 4, 2006 (gmt 0)

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



You still don't have a RewriteCond part.

wsmeyer

2:14 am on Oct 5, 2006 (gmt 0)

10+ Year Member



I don't know, I'm certainly not an expert on .htaccess stuff but I found an example in the Apache docs that was similar to what I needed, changed the parameters of the url and it woks perfectly.

William.