All things Shopify and commerce
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:
<script>
document.addEventListener('DOMContentLoaded', function() {
var redirectToMap = {
'/category.php?id=26/smart-shoes': '/collections/smart-shoes',
// Add more redirects as needed
};
var pathname = window.location.pathname + window.location.search;
var redirectTo = redirectToMap[pathname];
if (redirectTo) {
window.location.href = redirectTo;
}
});
</script>
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.
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025