如何将URL从“example.com/search/.../?folder=something”重定向到“example.com/something/search/.../”

时间:2014-03-02 23:50:03

标签: .htaccess url redirect url-rewriting

如何将URI从example.com/search/.../?folder=something重定向到example.com/something/search/.../

是否有htaccess规则?

1 个答案:

答案 0 :(得分:2)

您可以尝试将此规则作为第一条规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+([^?]+)\?folder=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.+?)/?$ /$2/?folder=$1 [QSA,L]