0

I've hosted my next js static site on apache server. I can't manage to remove trailing slash from my urls. I've also added trailingSlash: false to nextConfig.js. Here's my current .htaccess file.

RewriteEngine On
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
#Redirect www to non www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • _Aside:_ Your "www to non-www" redirect is in the wrong place - it should be at the very top of the file, not at the end. I'm curious, where did this code come from? It's obviously wrong in several respects, but it's _identical_ to the code in the linked (duplicate) question. – MrWhite Feb 18 '23 at 19:49

0 Answers0