1

There appears to be many questions like this here but can't find an answer that fits my current code:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ public/index.php [QSA,L]

This redirects everything to public/index.php which works fine but I want to get rid of the trailing slash so that example.com/foo/ becomes example.com/foo

1 Answer 1

1

You can insert a trailing slash removal code before your current rule:

RewriteEngine On

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

## forward all requests to public/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ public/index.php [L]
Sign up to request clarification or add additional context in comments.

5 Comments

The above code redirects foo/ to public/foo/. I need to "hide" public in browser URL.
Sorry I am using a boilerplate from a long time ago pastebin.com/sKp3nWvG
Yup still the same :(
Well it's in localhost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.