I am trying in my laravel 5.8 to make all my routes end with / and also to remove the www. from the beginning of the URL. those of the www I think I have achieved it this way:
# drop www in url
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
But I can't get it to put the /
at the end of my url. From what I have read, Laravel by default removes it because it understands that it is a directory. But I would like to force it to be put, for SEO
I'm trying to put it this way:
RewriteRule ^(.*)/$ $1 [L,R=301]
But without success.
Update
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# drop www in url
# www.guiapaladar.com
# RewriteEngine on
# RewriteCond %{HTTP_HOST} ^www.guiapaladar.com [NC]
# RewriteRule ^(.*)$ https://guiapaladar.com/$1 [L,R=301]
# Force Trailing Slash
# RewriteBase /
# RewriteRule ^(.*)/$ /$1 [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Thanks in advance and greetings
force www
You can add the following code
This will force the "www." in requests to the domain, if you need to delete the "www." of the domain you can use
Adjust the code to the domain you need to remove or add the "www."
Add "/" at the end of the URL
This will force the browser to put the "/" at the end of the URL. If it is caused by an error on the site you can use javascript
It can be useful
EDIT
If you need to exclude "/" from files with specific extensions you can use
This will exclude the slash "/" at the end of the URL to files with the extension:
...
Edit 2
Try changing your htaccess with this