views:

572

answers:

2

Hi,

I'm trying to use rewrite rules in my .htaccess to take user from an old link to a temporary new link (it's not a permanent new site, so I don't want a 301 redirect)

The following works for all the html pages and also the php pages without parameters, but it doesn't process the last example - a php page with parameters. Note that the directory structure is different on the new domain, but the parameters of the url are exactly the same. Is there something I can do with regular expressions to enable to rewriterule? I don't have too much experience writing my own reg expressions, so I'm not sure where to begin. Thanks!

My .htaccess file:

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Options -MultiViews
Options +FollowSymlinks
RewriteEngine on
RewriteRule invest/index.html http://example.org/new_file_structure/invest/index.html
RewriteRule index-old.html http://example.org/index.php
RewriteRule invest/i2/ap/row_I2_i_ap1.php http://example.org/new_file_structure/i2/ap/row_I2_i_ap1.php

##The following doesn't work:
RewriteRule subpages/view.php?d=i1_014 http://example.org/2010/view.php?d=i1_014 

Thanks, Jen

+1  A: 

Any GET parameters are stored in

%{QUERY_STRING}

you should be able to add that to your redirect URL.

RewriteRule subpages/view.php?d=i1_014 http://example.org/2010/view.php?d=i1_014&%{QUERY_STRING}

But if you don't want a 301, why are you pointing out a full URL? I think that way you enforce a 301. Why not just use /2010/view.php....?

Pekka
Hmm. Do you mean this: RewriteRule subpages/view.php?%{QUERY_STRING} http://example.org/2010/view.php?%{QUERY_STRING}I am pointing to a full url because the new page is located on a different domain.
Jen
Ah, all right. But if you use full `http://` URL, I'm 99% sure Apache will automatically make it a `301` and not an internal redirect. I may be wrong, though, if the same domain is managed on the same server - try it out and see what the browser does.
Pekka
I think you are actually right, but I guess it doesn't matter whether it's an external or internal redirect, I'm more focused on figuring out how to capture the GET parameters and use them to determine which url to redirect to. I tried using the %{QUERY_STRING} but it doesn't work - should it go AFTER the actually get parameters, or in place of?
Jen
Pekka
+1  A: 

You need to use RewriteCond in order to detect the query string:

RewriteCond %{QUERY_STRING} d=(.+)

And then you need to use a RewriteCond backreference in the form of %n:

RewriteRule subpages/view.php$ http://example.org/2010/view.php?d=%1
Ignacio Vazquez-Abrams
This works, thanks!
Jen