Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 301重定向-动态URL-保留查询字符串_Php_Regex_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php 301重定向-动态URL-保留查询字符串

Php 301重定向-动态URL-保留查询字符串,php,regex,.htaccess,mod-rewrite,redirect,Php,Regex,.htaccess,Mod Rewrite,Redirect,我在其他地方读了很多书,但我仍然在努力实现这个新的htaccess重定向。我尝试过各种版本的重写,但都没能成功。还有,我仍然对是否应该使用QSA感到困惑 我希望我的旧页面具有动态URL重定向到我设置的新目录/页面。问题是,我不想为我所有的州和国家写一个条目。我想保留现有的查询字符串 我试着从: http://example.com/olddir/detailsbyst.php?country=____&state=__&sd=____ http://example.com/NE

我在其他地方读了很多书,但我仍然在努力实现这个新的htaccess重定向。我尝试过各种版本的重写,但都没能成功。还有,我仍然对是否应该使用QSA感到困惑

我希望我的旧页面具有动态URL重定向到我设置的新目录/页面。问题是,我不想为我所有的州和国家写一个条目。我想保留现有的查询字符串

我试着从:

http://example.com/olddir/detailsbyst.php?country=____&state=__&sd=____ 
http://example.com/NEWDIR/detailsbyst.php?country=____&state=__&sd=____
我试过的最后一个版本是这个

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{QUERY_STRING} ^country=([A-Z­a-z­0-9­-]+)$ [NC]
RewriteCond %{QUERY_STRING} ^state=([A-Z­a-z­0-9­-]+)$ [NC]
RewriteCond %{QUERY_STRING} ^sd=([A-Z­a-z­0-9­-]+)$ [NC]
RewriteRule ^olddir/detailsbyst\.php$ http://example.com/newdir/detailsbyst.php [NC,QSA,L,R=301]
另一方面,一些旧的动态URL在查询字符串的末尾有&desc而不是&sd,因此对于这些URL,我希望将&desc转换为$sd


谢谢-Nick

如果您只想将
/olddir/
地址重定向到
/NEWDIR/
,您需要使用一个重写规则:

RewriteRule ^olddir(.*)$ /NEWDIR$1 [NC, L,R=301]
这应该可以做到: