Removing trailing slash from ALL URLs in site

后端 未结 3 1203
情深已故
情深已故 2020-12-06 07:52

I\'m kind of new to the whole .htaccess thing and I\'ve been trying to modify it so that none of my links will have trailing slashes at the end of their respective URLs. My

3条回答
  •  遥遥无期
    2020-12-06 08:32

    This works for me; removing all trailing slashes from all routes while emphasizing that REQUEST_URI starts with a slash (at least in .htaccess files):

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

    Just don't use %{REQUEST_URI} (.*)/$. Because in the root directory REQUEST_URI equals /, the leading slash, and it would be misinterpreted as a trailing slash.

    SOURCE: https://stackoverflow.com/a/27264788/2732184

提交回复
热议问题