Web Analytics Made Easy -
StatCounter htaccess - Remove trailing forward slash except for - CodingForum

Announcement

Collapse
No announcement yet.

htaccess - Remove trailing forward slash except for

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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

    Comment


    • #3
      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]

      Comment

      Working...
      X