Isapi Rewrite 301 redirect resolves 404 - circular link?

I am trying to use IIS Isapi Rewrite to do the following ...

I need seo-friendly URLs that will (silently) be converted back to application-friendly URLs, for example:

RewriteRule ^/seo-friendly-url/ /test/index.cfm [I,L]

Simple enough.

But I also need URLs already indexed in search engines (for example) so that 301 is redirected to a seo-friendly version. For example:

RewriteRule ^/test/index.cfm    /seo-friendly-url/ [I,R=301]

Each of these works is perfectly isolated. But when I have both in my .ini file, I get / seo-friendly-url / showing in my browser address bar, but they give me 404. (Yes, / test / index.cfm definitely exists!)

I know this looks like a circular link, but the first rule only rewrites the URL between IIS and the application - there is no redirect there, so I won’t beat Isapi Rewrite a second time. Or am I wrong about that?

I have enabled recording in Isapi Rewrite and I see the following:

HttpFilterProc SF_NOTIFY_PREPROC_HEADERS
DoRewrites
New Url: '/seo-friendly-url/'
ApplyRules (depth=0)
Rule 1 : 1
Result (length 15): /test/index.cfm
ApplyRules (depth=1)
Rule 1 : -1
Rule 2 : 1
Result (length 18): /seo-friendly-url/
ApplyRules: returning 301
ApplyRules: returning 1
Rewrite Url to: '/seo-friendly-url/'

Does anyone have any idea?

+3
source share
2 answers

With some trial and error, I came up with a solution for this.

Indicate that the redirection match is at the end of the line using the $ character:

RewriteRule ^/test/index.cfm$    /seo-friendly-url/ [I,R=301]

Make the rewritten URL trivially different from the redirect matching string - in this case adding the unnecessary "?":

RewriteRule ^/seo-friendly-url/ /test/index.cfm? [I,L]
0
source

, , .

  • . /seo -friendly,

  • , . /seo -friendly - , [R = 301, L], , - (L )

0

Source: https://habr.com/ru/post/1711338/


All Articles