简体   繁体   中英

Remove trailing slash and create query string with .htaccess

In my .htaccess file, I would like to remove the trailing slash from the URL without modifying the current setup for the query string.

I tried this in a two-step fashion, but it's not working as I expect:

# Remove trailing slash
RewriteRule ^(.+)/$ $1 [R=301]
# Create query string from canonical URL
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

Cheers

You can use:

RewriteEngine On
RewriteBase /site/dev/

## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 

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