简体   繁体   中英

php htaccess url encode/decode remove trailing slash

I'm using .htaccess to remove trailing slash from URI:

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

The website is built with Codeigniter and has three languages, where russian is one of them, that uses cyrillic chars in URI.I use urlencode for generating routes and urldecode to find the right page from database by URI.

Removing trailing slash works fine with english and german languages, but when I try add trailing slash to URI where cyrillic chars are used, I get 404 page. URI after removing / seems correct, but I can't understand why I get 404, the URL is the same as entered without trailing slash.

Use NE flag for not encoding:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/$ $1 [R=301,L,NE]

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