2

I've got this setup:

RewriteRule ^brands$ brands/ [R=301,L]
RewriteRule ^brands/$ /brands.php
RewriteRule ^brands/([A-ZÆØÅæøåa-z0-9-]+)-([0-9]+)/$ index.php?manufacturers_name=$1&manufacturers_id=$2 [L,QSA]
RewriteRule ^brands/([0-9]+)$ index.php?manufacturers_id=$1 [L]

How would I fix it so there's always a trailing slash on this. Those specific URLs?

example.com/brands/brand-id

So if I went to either example.com/brands/brand-id OR example.com/brands/brand-id/, it'll work as having a trailing slash?

TRiG
  • 10,148
  • 7
  • 57
  • 107
Dennis A
  • 71
  • 7
  • Possible duplicate of [Htaccess: add/remove trailing slash from URL](https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url) – Syntax Error Jan 18 '18 at 11:39
  • I only need it for those specific rules though, not the rest of the site. – Dennis A Jan 18 '18 at 11:40

1 Answers1

0

Replace your Rule with this

 RewriteRule ^brands/([0-9]+)/?$ index.php?manufacturers_id=$1 [L]

/? means that the / is optional in uri. Your rule will match both uri strings ending with or without a traling slash.

And to add the traling slash to specific uris,put the following before your existing rules

RewriteRule ^brands/[0-9]+$ %{REQUEST_URI}/ [L,R]

This will redirect /brands/123 to /brands/123/ .

Amit Verma
  • 40,709
  • 21
  • 93
  • 115