chubbyk
chubbyk

Reputation: 6302

Remove URL trailing slashes in .htaccess but keep if query string is present

I use this rule to remove trailing slash in URL:

RewriteRule ^(.*)/$ /$1 [L,R=301]

But this also redirects URLs with query string.

So it redirects :

http://www.example.com/something/?q=text

to

http://www.example.com/something?q=text

I need to keep URL unchanged if query string is present

Upvotes: 0

Views: 813

Answers (1)

anubhava
anubhava

Reputation: 785521

You can use this rule:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+?)/$ /$1 [L,R=301]

Upvotes: 3

Related Questions