Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    htaccess - Remove trailing forward slash except for

    I have the following in htaccess to remove trailing slashes:

    Code:
    #RewriteCond %{HTTP_HOST} !^\.example\.com$ [NC]
    #RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
    This works great, but I now need to add an exception to that rule. I have a folder (lets call it 'myfolder') that needs a trailing slash. Is it possible to ammend the above condition to allow this?

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    If it is a real directory you could go with..

    Code:
    RewriteCond %{REQUEST_FILENAME} !-d
    ...otherwise you could go with...

    Code:
    RewriteCond %{REQUEST_FILENAME} !=myfolder

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks Cags,

    In the end I went with this:
    Code:
    RewriteCond %{HTTP_HOST} !^\.example\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/myfolder/$
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •