How to resolve url issues in next.js

  1. Create a .htaccess file: Create a file named .htaccess in the root directory of your Next.js application.
  2. Add rewrite rules: Add the following rewrite rules to the .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /.next/server/pages/$1 [L]

These rules will redirect any requests that don’t match an existing file or directory to the .next/server/pages directory, where Next.js handles routing.

  1. Restart Apache: If you’re using Apache as your web server, restart Apache to apply the new rewrite rules.

Once you’ve completed these steps, you should be able to access your page using https://test.jjknowledgebase.com/previewpost without the .next/server/pages part in the URL.

Leave a comment

Your email address will not be published. Required fields are marked *