Only redirect when not in a certain folder ?

ISAPI_Rewrite is a powerful URL manipulation engine based on regular expressions
User avatar
Posts: 3
Joined: 22 Feb 2013, 05:45

Only redirect when not in a certain folder ?

13 Mar 2013, 09:58

Hi all,

I am trying use rewrite rules to remove any trailing slashes but only for certain folders on my site. This is because some folders (3rd party software on the site) require trailing slashes and so my rule sends browsers into a redirect loop when these folders are accessed.

Currently I have the following:

### make sure all URLs don't have a trailing slash
RewriteCond URL !^/icm.*
RewriteRule ^([^.?]+[^.?/])/((/|\?|\&).*)?$ $1$2 [RP,L]


If I take the RewriteCond line out, then the trailing slashes are removed correctly but browsing to the /icm folder goes into a redirect loop. However, if I leave the RewriteCond line the rule is ignored for everything.

The ISAPI 2 documentations states that "RewriteCond URL /icm.*" can be used to apply a rule just in the icm folder (and subfolders) so is it a case of the ! directive not working for RewriteCond ?

Anyone got any ideas ?

Regards,

Adam Brunt

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Only redirect when not in a certain folder ?

14 Mar 2013, 08:14

Hello, Adam

The issue is that negation in ISAPI_Rewrite won't work like this.
Try to use the following rule instead:

### make sure all URLs don't have a trailing slash
RewriteRule /(?!icm.*)([^.?]+[^.?/])/((?:\?|&).*)?$ $1(?2$2) [RP,L]

Return to ISAPI_Rewrite 2.x

Who is online

Users browsing this forum: No registered users and 9 guests