appending part of REQUEST_URI in redirect url

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 33
Joined: 18 Jul 2012, 07:50

appending part of REQUEST_URI in redirect url

28 Feb 2013, 06:27

Hi,

I am using 301 redirects like this.

Code: Select all
RewriteMap map txt:redirect.txt

RewriteCond %{HTTP:Host} ^(?:www\.)?example\.com$
RewriteCond %{REQUEST_URI} view/detail/id/(\d+)/(.*)
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) ${map:%1}? [NC,R=301,L]


it's working fine, but what i need is that if the url looks like
www.example.com/view/detail/id/3232/code/A135/anz/5
then the
code/A135/anz/5
part should be appended in redirect URL.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: appending part of REQUEST_URI in redirect url

28 Feb 2013, 11:12

Hello,

Try using:

Code: Select all
RewriteMap map txt:redirect.txt

RewriteCond %{HTTP:Host} ^(?:www\.)?example\.com$  [NC]
RewriteCond %{REQUEST_URI} view/detail/id/(\d+)/(.+)? [NC]
RewriteCond %{REQUEST_FILENAME} !-F
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) ${map:%1}/?%2%2? [NC,R=301,L]


Regards
Andrew

User avatar
Posts: 33
Joined: 18 Jul 2012, 07:50

Re: appending part of REQUEST_URI in redirect url

28 Feb 2013, 12:13

Hi,

It's working great but unfortunatly could not understand the
Code: Select all
/?%2%2?
in the last line. Can you please explain it a bit

for example what we are writing %2 twice

Thank you in advacne.

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: appending part of REQUEST_URI in redirect url

28 Feb 2013, 19:28

Let's break down it "?%2%2?"a little:

"?%2" - if %2 is there. And we've specified that it may not be there by having '?' at the end "(\d+)/(.+)?"
"%2" - inserts the vaule of (.+)
"?" - prevents appending of original querystring

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 5 guests