How can I successfully redirect my old PHP URLs to new Shopify URLs?

Topic summary

A user migrated their site from PHP to Shopify and encountered issues redirecting old URLs containing query parameters (e.g., /category.php?id=26/smart-shoes) to new Shopify collection URLs.

Core Problem:

  • Shopify doesn’t natively support redirects with query parameters (? and &)
  • Automatic URL encoding converts the path incorrectly (e.g., %2F for forward slashes)
  • Only 40% of redirects were successful using standard methods

Proposed Solutions:

  1. JavaScript Workaround (Initial Response):

    • Create a custom 404 page template (page.404.liquid)
    • Add JavaScript code to map old URLs to new destinations
    • Configure the 404 page in Shopify admin settings
    • Remove unsuccessful redirects from the URL Redirects section
  2. SEO-Optimized Approach (Later Contribution):

    • Use URL-encoded versions of query parameters (e.g., %2F for /)
    • Create redirects like /category.php?id=26%2Fsmart-shoes//collections/smart-shoes
    • This produces 301 (permanent) redirects instead of 302 (temporary), which is better for SEO

Status: The original poster acknowledged the initial solution but hasn’t confirmed implementation results.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

Hi,

I have moved my website from php to shopify. Earlier my php website ranked well but the url’s are different with existing one. I have redirected 40% of my Url’s but rest was unsuccessful. I don’t know is there any option for this or not.

My previous url is /category.php?id=26/smart-shoes

my new url is /collections/smart-shoes

My problem is that shopify not accepted my previous url type for redirection. it automatically converts my previous url path into this “/category.php?id=26%2Fsmart-shoes” which is incorrect.

kindly share the solutions.

Hi @preetcomm

Unfortunately, Shopify doesn’t support query parameters (? and &) in redirects, which is the reason you’re facing this problem.

However, there is a workaround to handle this situation using JavaScript on your 404 error page.

First, create a new page template in your Shopify theme, for example, “page.404.liquid”. Copy the content of the “page.liquid” template to the new “page.404.liquid” template.

Next, add the following JavaScript code at the end of the “page.404.liquid” file, before the closing </body> tag:


Replace the example URL in the redirectToMap object with your specific URLs. You can add more redirects by adding new lines with the format '/old-url': '/new-url',

Create a new page in your Shopify admin with the title “404” and assign it to the “page.404” template. You can leave the content of the page empty.

Go to Online Store > Navigation > URL Redirects, and remove any unsuccessful redirects that you have created earlier.

Finally, go to Online Store > Preferences > scroll down to the “404 error page” section, and select the “404” page you created earlier.

Now, when someone visits an old URL that isn’t redirected, they will be redirected to the corresponding new URL based on the JavaScript code added to the 404 error page.

Thanks

I will test it

This is a late reply but wanted to post up if anybody else comes across this.

Redirects with javascript will create a 302 response which indicates to Google that it’s a temporary move. You want to use a 301 redirect to the largest extent possible.

%2F is the url encoded version of a slash.

If you create a redirect for /category.php?id=26%2Fsmart-shoes then it will redirect when /category.php?id=26/smart-shoes is input in the browser using a 301 redirect.

1 Like