redirect with string parameter to new folder

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 11
Joined: 17 Aug 2015, 21:04

redirect with string parameter to new folder

07 Feb 2016, 05:59

I am not sure I have titled this thread correctly, but obviously the mods can edit the title if they feel it is needed.

Ok here is what I need to do

old url
http://domain.com/folder/page.php?string

new url
http://domain.com/go/string.php

I have gone round and round with this after reading a number of examples here in the forums, given up and came back to try another day and the best I have been able to come up with is
RewriteRule ^/folder/?page\.php$ http://domain.com/go/%1\.php [L,R=301]

which provides new url
http://domain.com/?string.php

There are 2 problems with that, it isn't in the sub-folder needed and it contains the "?"

I am 100% positive I have some bad syntax but not sure where I am screwing this up.

I do have the standard rules for wordpress to fix permalinks in place but have also tried the same thing on html sites and get the same kinds of results.

User avatar
Posts: 11
Joined: 17 Aug 2015, 21:04

Re: redirect with string parameter to new folder

07 Feb 2016, 06:36

Ooops, I think the string I posted was the wrong one but one of the many I tested.

I just tested it again and this rule DOES produces the results I posted above
RewriteRule ^/folder/?page\.php$ http://domain.com/go/%1/.php [L,R=301]

which provides new url
http://domain.com/?string.php

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: redirect with string parameter to new folder

10 Feb 2016, 12:42

Hello.

Please try this:

RewriteEngine On

RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^folder/page\.php$ /go/%1.php [NC, R=301]

User avatar
Posts: 11
Joined: 17 Aug 2015, 21:04

Re: redirect with string parameter to new folder

12 Feb 2016, 03:20

I do believe that did the trick.

I need to test this a little further after clear cache etc since first test worked but second failed and third test in different browser worked. (the fail is most likely a dirty cache)

I gotta say, The support here is just top notch all the way, and like support taught me a while back, any testing requires the use of additional browsers as well as cache clearing before you make up you mind whether something is working or not...

User avatar
Posts: 11
Joined: 17 Aug 2015, 21:04

Re: redirect with string parameter to new folder

12 Feb 2016, 04:00

Happy to report the code provided by Yaroslav does work perfectly, the reason my second test failed was due to not clearing cache, I have tested this with many different parameters from different machines running different OS's and different browsers and they all work just fine.

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: redirect with string parameter to new folder

15 Feb 2016, 08:41

Thank you for your kind words!

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 17 guests