How to redirect a URL from "example.com/search/.../?folder=something" to "example.com/something/search/.../"

StackOverflow https://stackoverflow.com/questions/22135339

Question

How to redirect a URI from example.com/search/.../?folder=something to example.com/something/search/.../?

Is there a htaccess rule?

Was it helpful?

Solution

You can try this rule as your first rule:

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top