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

前端 未结 3 1674
死守一世寂寞
死守一世寂寞 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:45

    Redirects request for all URLs ending in a / except for the root:

    RedirectMatch 301 ^(.+)/$ $1
    
    0 讨论(0)
  • 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]
    
    0 讨论(0)
  • 2020-12-08 03:53

    How about

    RewriteEngine On
    RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 
    
    0 讨论(0)
提交回复
热议问题