URL rewrite issue

I am having trouble with url rewriting.
I have a website https://mysite.com with Wordpress blog hosted at https://mysite.com/blog
My blog urls are like https://mysite.com/blog/my-story

Now I am building website in Vercel and I want to keep the blog urls same for SEO reasons so I am using URL re-writing in nextjs config file.
I am fetching blog from urls like https://app.mysite.com/blog/my-story but re-writing url as https://mysite.com/blog/my-story

When I run the vercel app, it shows the home page of the blog correctly and the url is shown as https://mysite.com/blog
But when I try to load individual blog pages, the url re-writing does not work and the URL shown as https://app.mysite.com/blog/my-story

So it looks like that for nested links in wordpress, url rewriting is not working. Instead of rewriting it is actually redirecting to the url.

My next.config.js has code:

async rewrites() {
    return [
      {
        source: '/blog/:path*',
        destination: 'https://app.mysite.com/blog/:path*',
      },      
    ];
  },

Am I doing something wrong?
Any help?

Hi, @rajmedma-gmailcom! Welcome to the Vercel Community :smile:

Your rewrite configuration looks correct. The issue you’re experiencing is likely not due to the rewrite rule itself. The behavior you’re seeing (URL changing to app.mysite.com) suggests a redirect is happening, not a rewrite. Some possible causes:

  1. WordPress settings or plugins causing redirects
  2. Conflicting Vercel project settings
  3. Client-side routing in your Next.js app interfering with blog URLs
  4. Next.js middleware affecting blog post routing

Could you check the following?

  1. Verify WordPress isn’t redirecting
  2. Check Vercel project for conflicting rules
  3. Examine network requests in browser dev tools
  4. Ensure WordPress can handle requests from your Vercel domain

If these don’t resolve the issue, more details about your setup would be helpful for further troubleshooting. Let us know how you get on!

1 Like

I also don’t see any deployment on your Vercel dashboard. Can you share the deployment link?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.