0

I've been trying to solve this for some time, and have tried a few suggestions which I found, but none of them seem to work

I would like to try and force a slash at the end of the URL for any page visited on my site, so rather than

www.example.com/about

it forces

www.example.com/about/

My .htaccess looks like

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ local/ [L]
RewriteRule (.*) local/$1 [L]
</IfModule>

Could anyone help?

MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • This doesn't appear to be a _simple_ "force trailing slash" issue, since you appear to be rewriting all requests to a `local` subdirectory, so a request for `/about` is actually served by `/local/about/`. But how does `/about/` (or `/local/about/`) actually handle the request? Do you have a second router in `/local` that manages this? Or is `/local/about/` a physical directory and you serving a directory index document, such as `/local/about/index.html`? – MrWhite Apr 04 '22 at 12:01

1 Answers1

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

try this

Moosike
  • 37
  • 6
  • The only issue is that it seems to rewrite things like the stylesheet location So I used RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*[^/])$ /$1/ [L,R=301] RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L] –  Apr 04 '22 at 10:23
  • @marcus "So I used" - So, does that resolve it? (Although I imagine it doesn't since you are rewriting all requests to a subdirectory immediately afterwards.) – MrWhite Apr 04 '22 at 11:31