alex
alex

Reputation: 490283

.htaccess - Rule being ignored

I use this line in my .htaccess file to automatically add a trailing slash if not present

rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ /$1/ [NC,R=301]

This works fine, until I use these lines to redirect all requests to not files or dirs to index.php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php

This now forwards the page, but doesn't add the trailing slash.

Does anyone know why this wouldn't be working?

Upvotes: 1

Views: 624

Answers (1)

alex
alex

Reputation: 490283

I figured it out, I added the L for last rule to the first rewriteRule.

So it now looks like this

rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ /$1/ [NC,R=301,L]

Upvotes: 1

Related Questions