开发者

Redirect URL with RewriteRule if php url has parameters?

开发者 https://www.devze.com 2022-12-17 06:47 出处:网络
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)

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 expressi开发者_StackOverflowons, 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


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


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....?

0

精彩评论

暂无评论...
验证码 换一张
取 消