2 rewrites - 1 overrides the other

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 1
Joined: 19 Mar 2012, 12:48

2 rewrites - 1 overrides the other

19 Mar 2012, 12:50

Hi

I have the following rewrite in place - however the first rule is always used. How do I get the second rule to work?

RewriteCond %{QUERY_STRING} ^p=([^&]+)&title=(.*)$
Rewriterule ^inner\.asp$ /%1/%2? [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /inner.asp?p=$1&title=$2 [NC,L]

RewriteCond %{QUERY_STRING} ^p=([^&]+)&title=(.*)$
Rewriterule ^area\.asp$ /%1/%2? [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /are.asp?p=$1&title=$2 [NC,L]

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

Re: 2 rewrites - 1 overrides the other

20 Mar 2012, 07:57

Well, as you can see you have 2 sets or rules. 2 rules in each.
The second rule's pattern of each set is exactly the same - ^([^/]+)/([^/]+)$.
So the first set will always work, while second will perform only the first rule, not second.

I'd suggest using the following set of rules:

Code: Select all
RewriteCond %{QUERY_STRING} ^p=([^&]+)&title=(.*)$
Rewriterule ^inner\.asp$ /i/%1/%2? [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^i/([^/]+)/([^/]+)$ /inner.asp?p=$1&title=$2 [NC,L]

RewriteCond %{QUERY_STRING} ^p=([^&]+)&title=(.*)$
Rewriterule ^area\.asp$ /a/%1/%2? [NC,R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^a/([^/]+)/([^/]+)$ /are.asp?p=$1&title=$2 [NC,L]


Regards
Andrew

User avatar
Posts: 27
Joined: 04 Dec 2012, 21:06

Re: 2 rewrites - 1 overrides the other

04 Dec 2012, 21:32

Does this depend on the file name you used?

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

Re: 2 rewrites - 1 overrides the other

04 Dec 2012, 22:36

Of course, you'll have to adjust it for your personal needs.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 45 guests