1

The following .htaccess rule un-matches string admin and adds a trailing slash(/) to that URL if admin is not found in the URL

RewriteRule ^((?!admin).)*((?!\/).)$ /$1/ [L,R] 

But it has an error, and it is

  http://www.domain.com/index

should result to : http://www.domain.com/index/

But currently it is resulting: http://www.domain.com/inde/

Please find a solution to correct it. Thanks Very much .

CSᵠ
  • 10,049
  • 9
  • 41
  • 64
SP Singh
  • 416
  • 4
  • 18

1 Answers1

1

Your expression captured the last character in a group.

This will solve the issue:

RewriteRule ^(?!.*admin)(.*?)\/?$ /$1/ [L,R] 

Check out the explained demo here: http://regex101.com/r/kL6pV1

Note: this will invalidate any URL that contains admin, not necessarily starting with admin

CSᵠ
  • 10,049
  • 9
  • 41
  • 64