3

I want to do a 301 redirect from old_page.php to new_page.php and keep all query strings if they exist.

so old_page.php would redirect to new_page.php

old_page.php?test=1 would redirect to new_page.php?test=1

Here is what I have below, but it's a 404 error.

RewriteEngine on 
RewriteRule ^old_page.php(.*) new_page.php$1 [R=301,L]
Don Sevcik
  • 915
  • 1
  • 8
  • 23
  • And this was to hard for you? https://www.google.com/search?q=rewrite+keep+query+string – CBroe Apr 27 '14 at 23:45
  • possible duplicate of [How can I mod\_rewrite and keep query strings?](http://stackoverflow.com/questions/12873137/how-can-i-mod-rewrite-and-keep-query-strings) – CBroe Apr 27 '14 at 23:45
  • I saw that thread. Still not working: RewriteRule (.*)/old_page.php(.*) $1/new_page.php$2 [R=301,QSA] – Don Sevcik Apr 27 '14 at 23:59
  • Where did the `(.*)/` in front come from all of a sudden, and what exactly are you hoping to match _after_ `old_page.php`? – CBroe Apr 28 '14 at 00:09
  • Here is what I have now which is not working either: RewriteRule ^old_page.php(.*) new_page.php$1 [R=301,QSA] – Don Sevcik Apr 28 '14 at 00:10
  • There will be no `$1`, since there is nothing behind `old_page.php` to match. – CBroe Apr 28 '14 at 00:20
  • This worked: Redirect 301 /old_page.php /new_page.php – Don Sevcik Apr 28 '14 at 00:32

1 Answers1

8

This worked:

Redirect 301 /old_page.php /new_page.php
Don Sevcik
  • 915
  • 1
  • 8
  • 23
  • Do you have any ideas how to do the same thing but also have a hard coded QS parameter on the second url like this: http://stackoverflow.com/questions/23607633/transfer-a-querystring-between-2-domains-using-an-htaccess-301 – James Wilson May 12 '14 at 11:34