Remove trailing slash using .htaccess except for home / landing page

前端 未结 3 1684
死守一世寂寞
死守一世寂寞 2020-12-08 03:06

I\'ve successfully modified my .htaccess file to remove trailing slashes on most pages but I\'m wondering how to exempt my home page/directory? For example:

domain.

3条回答
  •  既然无缘
    2020-12-08 03:51

    OK. After a bunch of trial and error I answered my own question.

    The third line denotes that there has to be something in the URI in order to perform the redirect thus not redirecting if the url just contains the initial slash.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} (.*)$
    RewriteRule ^(.+)/$ http://www.domain.com/$1 [R=301,L]
    

提交回复
热议问题