简体   繁体   English

301重定向-动态网址-保留查询字符串

[英]301 redirect - Dynamic urls - Keep query strings

I've done a lot of reading here on other places but I'm still struggling with this new htaccess redirect I'm trying to implement. 在其他地方,我已经做了很多阅读,但是我仍在努力尝试实现的新htaccess重定向。 I've tried various versions of the rewrite but can't get it to work. 我尝试了各种版本的重写,但无法正常工作。 Also, still confused on whether I should use QSA or not. 另外,对于我是否应该使用QSA仍然感到困惑。

I want my old pages which feature dynamic urls to redirect to the new directory/page I have setup. 我希望具有动态url的旧页面重定向到我已设置的新目录/页面。 The thing is, I don'w want to write an entry for all of the states and countries I have. 问题是,我不想为我拥有的所有州和国家写一个条目。 I want to keep the exiting query string. 我想保留现有的查询字符串。

I'm trying to go from: 我试图从:

http://example.com/olddir/detailsbyst.php?country=____&state=__&sd=____ 
http://example.com/NEWDIR/detailsbyst.php?country=____&state=__&sd=____

The last version I tried was this 我尝试的最后一个版本是这个

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]

On a related note, some of the old dynamic urls have &desc instead of &sd at the end of the query string, so for those urls I would want to convert the &desc to $sd 与此相关的是,一些旧的动态url在查询字符串的末尾有&desc而不是&sd,因此对于这些URL,我想将&desc转换为$ sd

Thanks - Nick 谢谢-尼克

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

RewriteRule ^olddir(.*)$ /NEWDIR$1 [NC, L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM