remove trailing slash from URL in htaccess

后端 未结 2 995
北恋
北恋 2020-12-12 02:47

I have my htaccess configured to work in conjunction with a URL Router I\'ve written in PHP. I\'m trying to remove a trailing slash if seen from the URL except the root url

相关标签:
2条回答
  • 2020-12-12 03:19

    Insert this rule just below RewriteEngine On:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+?)/$ /$1 [R=302,NE,L]
    
    0 讨论(0)
  • 2020-12-12 03:21

    For those who are still running into this problem, I solved mine by adding a question mark just after the slash before the dollar sign, like this:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+?)/?$ /$1 [R=302,NE,L]
    
    0 讨论(0)
提交回复
热议问题