简体   繁体   中英

add .htaccess trailing slash

I'd like to put a trailing slash to my url with .htaccess just in these 3 cases:

  1. The part after the last slash doesn't contain a ? char
  2. The part after the last slash doesn't contain a . char
  3. The last url char is not a / char

I'd like to add those rules to my existing .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.* - [NC,L]
RewriteRule ^.* index.php [NC,L]
RewriteCond %{QUERY_STRING} ^$    [NC]
RewriteRule ^((.*/)?[^/\.]+)$ /$1/ [R,L]
RewriteRule ^(.*?[^/\?\.])$ http://example.com/$1/ [L]

Should do what you're looking for. Just add it right below RewriteEngine On in your existing file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM