如果php url有参数,用RewriteRule重定向URL?

Jen*_*Jen 2 php .htaccess mod-rewrite

我正在尝试在我的.htaccess中使用重写规则将用户从旧链接带到临时新链接(它不是永久性新网站,所以我不想要301重定向)

以下适用于所有html页面以及没有参数的php页面,但它不处理最后一个示例 - 带参数的php页面.请注意,新域上的目录结构不同,但url的参数完全相同.我可以使用正则表达式来执行重写吗?我没有太多编写自己的reg表达式的经验,所以我不知道从哪里开始.谢谢!

我的.htaccess文件:

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 
Run Code Online (Sandbox Code Playgroud)

谢谢,Jen

Ign*_*ams 5

您需要使用RewriteCond以检测查询字符串:

RewriteCond %{QUERY_STRING} d=(.+)
Run Code Online (Sandbox Code Playgroud)

然后你需要以下列形式使用RewriteCond反向引用%n:

RewriteRule subpages/view.php$ http://example.org/2010/view.php?d=%1
Run Code Online (Sandbox Code Playgroud)