Remove Trailing Slash from Sub-directory Folder Apache 1.3.42 DirectorySlash Off .htaccess

后端 未结 1 1388
孤城傲影
孤城傲影 2021-01-16 09:11

I’m trying to remove the trailing slash from my sub-directory folders in Apache 1.3.42 however the command DirectorySlash Off is not supported in my version of Apache when I

1条回答
  •  生来不讨喜
    2021-01-16 09:52

    You need to add a couple of other rules besides removing the trailing slash. With DirectorySlash Off, the redirect from no slash to trailing slash stops, but if you access any directory, it will print the contents of the directory instead of displaying the index file.

    This means you must internally add a trailing slash to directories. So change these lines:

    #removing trailing slash
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ $1 [R=301,L]
    

    To:

    DirectorySlash Off
    
    #removing trailing slash    
    RewriteCond %{THE_REQUEST_FILENAME} \ /(.*)/(\ |$|\?)
    RewriteRule ^(.*)/$ $1 [R=301,L]
    
    # internally add the slash back
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule ^(.*)$ /$1/ [L]
    

    0 讨论(0)
提交回复
热议问题